如何在matplotlib图中更改xticks字体大小 [英] how to change xticks font size in a matplotlib plot

查看:2118
本文介绍了如何在matplotlib图中更改xticks字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

ax=df_pivoted.plot(figsize=(30,15),linewidth=5)
plt.xticks( rotation=45)
plt.tick_params(labelsize = 20)
plt.xlabel('transaction_date', fontsize=20)
plt.grid(True)
plt.title('daily sale graph test_id=505 ',fontdict={'fontsize':30})
legend = ax.legend(loc=0, ncol=1, bbox_to_anchor=(0, 0, 1,1),fancybox=True,shadow=False,title='variations',prop={'size':30})


plt.setp(legend.get_title(),fontsize='30')
xposition = c12_days
for xc in xposition:
    ax.axvline(x=xc, color='g', linestyle='--')

plt.show()

上面的代码产生以下图形,其中我在x轴上有日期,但问题是,正如您所见,日的大小很小,但JUL和AUG较大,我为xticks和tick_params尝试了不同的字体大小,但没有看到任何重大变化.我如何更改代码以使日数与7月和8月一样大?

above code produce following graph where i have dates in x axis but the problem is that as you can see days have very small size but JUL and AUG are bigger i have tried different font sizes for xticks and tick_params but have not seen any major change. how can i change the code to have day numbers as big as JUL and AUG?

推荐答案

尝试使用

Try to use tick_params function like here:

ax = plt.gca()
ax.tick_params(axis = 'both', which = 'major', labelsize = 24)
ax.tick_params(axis = 'both', which = 'minor', labelsize = 16)

您可以指定"x"或"y"之类的轴,而不是"both".

You may specify axis like 'x' or 'y' instead of 'both'.

这篇关于如何在matplotlib图中更改xticks字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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