向分组小提琴图添加标签 matplotlib
我在同一轴上有 3 组 3 把小提琴(所以 9 个小提琴图)的图,我想给这些组贴上标签,这是我的尝试:
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])
我按预期得到了小提琴图,但我不知道如何添加标签正确。我收到错误:
module 'matplotlib.pyplot' has no attribute 'set_xticklabels'
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)