[英]How i can sort histogram bar in ascending/descending order of seaborn?
[英]sort histogram columns order with seaborn
我想分析我们团队的开发源代码质量,所以我制作了一个直方图来指示程序错误的严重程度。 我想按严重性组织列的顺序(低 -> 高或反向)
我有一张这样的桌子:
使用 seaborn 我有这个直方图
sns.displot(data = incidents, x = 'Severity', order = )
使用一些丑陋的代码+ barplot 我有这个。 但我想知道有没有更好的方法。
severity = pd.DataFrame(incidents[].value_counts().sort_index())
severity.plot(y = 'severity', kind = 'bar')
要设置分类值的顺序,您可以使用 pandas Categorical 将顺序设置为您喜欢的顺序并在绘图前对其进行排序。 下面的示例应该为您执行此操作...
incidents.Severity = pd.Categorical(values=incidents.Severity, categories=['Critical', 'High', 'Medium', 'Low']) ## Set the order for the column as you want
incidents.sort_values(['Severity'], inplace=True) ## Sort the column
sns.displot(data = incidents, x = 'Severity') ## and plot
Plot
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.