我想创建一个可变宽度x轴箱子在Seaborn条形图。与此图表类似: 我所有的宽度都会加起来达到100%,但我似乎无法找到如何通过Seaborn完成此目标的示例。有任何想法吗?可变宽度barplot与seaborn
1
A
回答
1
这里可能有几个可能的答案。在seaborn barplot中,可以使用几个参数的组合:“宽度”(条的宽度值),“左”(x轴上的位置值,这是强制参数)和“对齐”。
一个非常简单的例子:
import seaborn as sns
data = [7, 3, 15]
widths = [1, 5, 3]
left = [0, 1, 6]
sns.plt.bar(left, data, width = widths, color=('orange','green','blue'),
alpha = 0.6, align='edge', edgecolor = 'k', linewidth = 2)
注意,“左”(酒吧位置)应当对应于宽度,以使杆到刚好接触和不重叠。
+0
通过使用'sns.plt.bar',你可以调用matplotlibs'plt.bar'函数。这与海豹无关。 – ImportanceOfBeingErnest
0
如果你想使用Seaborn为barplot,您需要更改的吧矩形的宽度(补丁)之后(这是通过matplotlib面向对象接口,完成按this answer):
import seaborn as sns
iris = sns.load_dataset('iris')
ax = sns.barplot('species', 'sepal_width', data=iris)
widthbars = [0.3, 0.6, 1.2]
for bar, newwidth in zip(ax.patches, widthbars):
x = bar.get_x()
width = bar.get_width()
centre = x + width/2.
bar.set_x(centre - newwidth/2.)
bar.set_width(newwidth)
你也可以在matplotlib创建一个类似barplot直接:
import matplotlib.pyplot as plt
widths = [0.3, 0.6, 1.2]
for x_pos, (species_name, species_means) in enumerate(iris.groupby('species').mean().groupby('species')):
plt.bar(x_pos, species_means['sepal_width'], widths[x_pos])
相关问题
- 1. 如何在seaborn barplot上设置宽度
- 2. ggplot2 barplot中的可变宽度条R
- 3. 将seaborn barplot与matplotlib.plot结合()
- 4. Seaborn Distplot和Barplot
- 5. Seaborn Barplot - 显示值
- 6. ggplot2 barplot相同宽度
- 7. 阴影的宽度线barplot
- 8. 有回归线的Seaborn barplot
- 9. 项目与可变宽度上GridLayoutManager
- 10. 控制一个barplot的总宽度
- 11. 在barplot中精确控制条宽度
- 12. Matplotlib/Seaborn barplot - x轴中的字符串
- 13. Seaborn解决方法色调barplot
- 14. 如何更改顺序barplot seaborn
- 15. 删除Seaborn barplot图例标题
- 16. Seaborn使用数据框的水平barplot
- 17. Horizontallist可变宽度
- 18. 忽略宽度可变
- 19. Bxslider可变/增量宽度
- 20. css可变宽度2盒
- 21. 可变宽度网站
- 22. jQuery可变宽度滑块
- 23. Highchart提示可变宽度
- 24. XTickLabel可变intervalls在barplot
- 25. preg_replace()与可变顺序的src,高度和宽度
- 26. 展开与可变高度和宽度的div
- 27. sapui5 VizFrame与响应网格可变宽度/跨度
- 28. 中心两个可变宽度的CSS divs与固定与
- 29. 如何增加seaborn facetgrid图中xaxis刻度之间的宽度?
- 30. 两个固定宽度区间之间的可变宽度div(最小宽度)
没有理由使用seaborn条形图用于这一目的。改为使用'pyplot.bar'。 – ImportanceOfBeingErnest