在 matplotlib.pyplot 中,如何使用交错条形图绘制两个数据集? [英] In matplotlib.pyplot, how to plot two datasets using interleaved bar graphs?

查看:76
本文介绍了在 matplotlib.pyplot 中,如何使用交错条形图绘制两个数据集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历思维统计,我想在视觉上比较多个数据集.从书中的例子中可以看到,通过使用本书作者提供的模块,可以为每个数据集生成不同颜色的交错条形图,如何在pyplot中获得相同的结果?

I am going through Think Stats and I would like to compare multiple data sets visually. I can see from the book examples that it is possible to generate an interleaved bar graph with a different color for each data set by using a module provided by the book author, how to obtain the same result in pyplot?

谢谢
通努兹

推荐答案

多次调用bar函数,每个系列一次.您可以使用 left 参数控制条形的左侧位置,您可以使用它来防止重叠.

Call the bar function multiple times, one for each series. You can control the left position of the bars using the left parameter, and you can use this to prevent overlap.

完全未经测试的代码:

pyplot.bar( numpy.arange(10) * 2, data1, color = 'red' )
pyplot.bar( numpy.arange(10) * 2 + 1, data2, color = 'red' )

与绘制数据的位置相比,绘制的Data2将向右移动.

Data2 will be drawn shifted over the right compared to where data one will be drawn.

这篇关于在 matplotlib.pyplot 中,如何使用交错条形图绘制两个数据集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆