热线电话:13121318867

登录
2020-04-20 阅读量: 2959
countplot 怎么对这些柱子进行排序呢

如图,我想对图片里的柱子进行排序,该怎么设置参数呢?

用里面的参数order,但order参数只接受类别字符串列表,就是把x轴上的以列表的形式传入里面。

所以在写的时候需要转换一下。

如以泰坦尼克号为例:

import pandas as pd

import seaborn as sns

import matplotlib.pyplot as plt

sns.set(style='darkgrid')

titanic = sns.load_dataset('titanic')

sns.countplot(x = 'class',

data = titanic,

order = titanic['class'].value_counts().index)

plt.show()

图片里的柱子就从大到小的顺序排序了

17.7288
1
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子