我有这个代码,我试图做一个图表。列表中的所有值都正确。但是,我在x轴有问题。首先,前两个节拍之间有间隙。我阅读了他们网站上所有的matplotlib,但找不到任何有用的东西来解决这个问题。我对xticks的功能很困惑。This is my graph
plt.bar(Valloc1,[diabete[w] for w in sorted(diabete.keys())], width=0.2,)
plt.bar(Valloc2,[not_diabete[w] for w in sorted(not_diabete.keys())], width=0.1, )
plt.xticks(all_years, rotation = '65')
plt.legend(['Diabete','Not-Diabete'])
plt.xlabel('Years')
plt.ylabel('# of patients')
plt.legend()
plt.show()
我试过这条线,但一切都变糟了。
plt.xticks(range(all_years),all_years, rotation = '65')
我也希望这两条边不重叠。就像这样: Bars side-by-side
我的变量是:
Valloc1 = [i for i in range(52)]
diabete = {{1967: 5, 1986: 13, 1985: 9, 1996: 5, 1984: 10, 1987: 6, 1991: 8...}
下面是一个如何解决问题的例子。由于您没有提供数据,我首先在下面的示例中生成一些随机数据,然后将其可视化为您要求的条形图:
结果如下:
相关问题 更多 >
编程相关推荐