【发布时间】:2018-11-14 23:19:07
【问题描述】:
我有以下代码来绘制数据框的内容。
使用 pandas 和 matplotlib:
thedata = {'2013':[0.0,0.0]
,'2014':[0.0,0.0]
,'2015':[0.0,0.0]
,'2016':[1,0.0]
,'2017':[0.0,0.0]
,'2018':[1,0.0]}
my_df = pd.DataFrame(thedata, index=['Green cars','Red cars'])
plt.figure(figsize=(7,3))
my_ax = plt.gca()
my_ax.clear()
my_ax.yaxis.set_major_locator(MaxNLocator(integer=True))
my_df.transpose().plot(kind='bar'
, stacked=True
, ax=my_ax
).grid(True,'major','y')
my_ax.legend(loc=9, bbox_to_anchor=(0.5, -0.1), frameon=False, ncol=2, fontsize=12 )
plt.title('All the cars', fontsize = 12 )
my_ax.set_xticklabels(my_ax.get_xticklabels(),rotation='horizontal', fontsize=12)
# my_ax.set_yticklabels(my_ax.get_yticklabels(),fontsize=12)
最后一行被注释掉以显示输出。我想将 y 轴标签的字体大小增加到与 x 相同,但是当我取消注释该行并运行它时,y 轴标签就消失了,那里什么也没有显示。
为什么会发生这种情况,我该如何解决?
编辑:- 创建数据框;熊猫 0.23.0,matplotlib 2.2.2
【问题讨论】:
-
您能否通过在代码中定义数据框并说明您使用的是哪个版本的 matplotlib 和 pandas 来使这个可重现?见minimal reproducible example。
-
编辑帖子以包含此内容
标签: python pandas matplotlib