根据分布的宽敞,在matplotlib中更改小提琴图的颜色
我一直在尝试使用Python中的Matplotlib库来绘制一个漂亮的小提琴图,以展示我的数据。这是我使用的代码:
ax.violinplot(vdistances,showmeans=False,showmedians=True)
ax.set_title('Distance analysis for molecule 1')
ax.set_xlabel('Atomic distances')
ax.set_ylabel('Distances in Amstrongs')
ax.set_xticks([x for x in range(1,len(distances)+1)])
plt.show()
这就是我想到的:
我一直想知道的是,是否可以为每个小提琴分配相同颜色的不同色调关于分布的宽敞,因此数据的分散程度越多。
I have been trying to work on plotting a nice violin plot to present my data using Matplotlib library in Python. This is the code I have used:
ax.violinplot(vdistances,showmeans=False,showmedians=True)
ax.set_title('Distance analysis for molecule 1')
ax.set_xlabel('Atomic distances')
ax.set_ylabel('Distances in Amstrongs')
ax.set_xticks([x for x in range(1,len(distances)+1)])
plt.show()
And this is what I have come up with:
What I have been wondering is if it is possible to assign different tones of the same color to each of the violins depending on how broad the distribution is, and so the more disperse the data is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以循环穿过生成的小提琴,提取其高度并使用它来设置颜色:
You could loop through the generated violins, extract their height and use that to set a color: