无法制作Seaborn小提琴图的水平方向[Python3.X]

7
使用Seaborn,我可以创建一个小提琴图。将其变成垂直方向没有问题。但是我想要一个水平的小提琴图。我看到建议在传递参数时只需交换x和y即可(链接1),但这样做并不能使小提琴图旋转90度。以下是一个简单的例子:violinplot函数。
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
categories = pd.Series(['2008', '2008', '2008', '2009', '2009' ])
values     = pd.Series(np.random.normal(0,1, 5))
sns.violinplot( x=categories, y=values, linewidth=5)
plt.show()
sns.violinplot( y=categories, x=values, linewidth=5)
plt.show()

这两个图表。第一个是垂直小提琴图,符合预期。但第二个不是相应的水平小提琴图。调用第二个图表的命令有什么问题?

enter image description here

2个回答

12

您可以通过在sns.violinplot中设置orient='h'来使第二个图水平显示:

sns.violinplot(y=categories, x=values, linewidth=5, orient='h')
plt.show()

在此输入图像描述

有关详细信息,请参见seaborn.violinplot文档


由于某种原因,在示例中没有提到 orient 选项,尽管在参考文献中有提到。 - vlsd

2

试试这个:

sns.violinplot(y=categories, x=values, linewidth=5, orient='h')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接