Python 如何在 matplotlib 图中更改 xticks 字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45710545/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to change xticks font size in a matplotlib plot
提问by chessosapiens
i have the following code :
我有以下代码:
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()
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?
上面的代码生成以下图表,其中我在 x 轴上有日期,但问题是,正如您看到的那样,天的尺寸非常小,但 JUL 和 AUG 更大,我尝试了不同的 xticks 和 tick_params 字体大小,但没有看到任何重大变化。我如何更改代码以具有与 JUL 和 AUG 一样大的天数?
回答by Serenity
Try to use tick_params
functionlike here:
尝试使用如下tick_params
函数:
ax = plt.gca()
ax.tick_params(axis = 'both', which = 'major', labelsize = 24)
ax.tick_params(axis = 'both', which = 'minor', labelsize = 16)
You may specify axis like 'x' or 'y' instead of 'both'.
您可以指定像 'x' 或 'y' 之类的轴而不是 'both'。