sanaz sanaz - 1 year ago 187
Python Question

how to change xticks font size in a matplotlib plot

i have the following code :

plt.xticks( rotation=45)
plt.tick_params(labelsize = 20)
plt.xlabel('transaction_date', fontsize=20)
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})

xposition = c12_days
for xc in xposition:
ax.axvline(x=xc, color='g', linestyle='--')

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?

enter image description here

Answer Source

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)

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download