无法使 seaborn 小提琴情节水平 [Python3.X]
Cannot make seaborn violin plot horizontal [Python3.X]
使用 Seaborn,我可以创建一个 .使其垂直是没有问题的。但我想要一个水平的小提琴情节。我看到了 it is advised to just switch x and y when passing parameters in the violinplot
函数。
我希望得到相同的小提琴情节,只是旋转了 90 度,我无法通过切换 x 和 y 来实现这一点。这是一个简单的例子:
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()
这两张图。首先是竖版小提琴情节,符合预期。但第二个不是类似的水平小提琴情节。调用第二个绘图的命令有什么问题?
试试这个:
sns.violinplot(y=categories, x=values, linewidth=5, orient='h')
您可以通过在 sns.violinplot
中设置 orient='h'
将第二个绘图设置为水平:
sns.violinplot(y=categories, x=values, linewidth=5, orient='h')
plt.show()
有关详细信息,请参阅 seaborn.violinplot
documentation。
使用 Seaborn,我可以创建一个 .使其垂直是没有问题的。但我想要一个水平的小提琴情节。我看到了 it is advised to just switch x and y when passing parameters in the violinplot
函数。
我希望得到相同的小提琴情节,只是旋转了 90 度,我无法通过切换 x 和 y 来实现这一点。这是一个简单的例子:
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()
这两张图。首先是竖版小提琴情节,符合预期。但第二个不是类似的水平小提琴情节。调用第二个绘图的命令有什么问题?
试试这个:
sns.violinplot(y=categories, x=values, linewidth=5, orient='h')
您可以通过在 sns.violinplot
中设置 orient='h'
将第二个绘图设置为水平:
sns.violinplot(y=categories, x=values, linewidth=5, orient='h')
plt.show()
有关详细信息,请参阅 seaborn.violinplot
documentation。