0

I have a plot of 3 groups of 3 violins (so 9 violin plots) on the same axis and I want to label the groups, here is my attempt:

ax = plt.violinplot([method1[:,0].flatten(),method2[:,0].flatten(),method3[:,0].flatten()],positions= [1,2,3],showmeans=True,showmedians=False)
ax = plt.violinplot([method1[:,1].flatten(),method2[:,1].flatten(),method3[:,1].flatten()],positions=[5,6,7],showmeans=True,showmedians=False)
ax = plt.violinplot([method1[:,2].flatten(),method2[:,2].flatten(),method3[:,2].flatten()],positions=[9,10,11],showmeans=True,showmedians=False)


#positions = (([1,2,3],[5,6,7],[9,10,11]))
#labels = ( "method 1", "method 2","method 3")
#plt.xticks(positions = [2,6,10], labels)

ax.set_xticklabels(['method 1','method 2','method 3'])
ax.set_xticks([2,6,10])

I get the violin plots as intended but I can't figure out how to add the labels correctly. I get the error:

module 'matplotlib.pyplot' has no attribute 'set_xticklabels'
11
  • Try this: ax.xticks([2, 6, 10], labels=['method 1','method 2','method 3']) Commented Mar 8, 2022 at 12:43
  • 1
    Hi, what was the error with plt.xticks([2,6,10], ['method 1','method 2','method 3'])? I thought that should work. Commented Mar 8, 2022 at 12:45
  • @duca It said positional argument follows keyword argument with square or round brackets and points to the comma before labels Commented Mar 8, 2022 at 12:55
  • @r-beginners I get 'dict' object has no attribute 'xticks' Commented Mar 8, 2022 at 12:56
  • 1
    Oh, now it works with that when I change the numbers - thanks! Commented Mar 8, 2022 at 13:08

1 Answer 1

1
positions = (2, 6, 10)
labels = ( "m1", "m2","m3")
plt.xticks(positions, labels)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.