Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change xticks font size in a matplotlib plot [duplicate]

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?

enter image description here

like image 380
chessosapiens Avatar asked Aug 16 '17 10:08

chessosapiens


People also ask

How do I make Xticks bigger in Matplotlib?

To make longer subplot tick marks in matplotlib, we can use tick_params() method for minor and major ticks length and width.

How do I change the font size in Matplotlib?

Changing Font Sizes in Matplotlib Using FontsizeEvery Matplotlib function that deals with fonts, such as the ones we used above, has a parameter named fontsize= to control the font size. This means when we set, say, a title using the . set_title() function, we can pass in an argument to specify the font size.

What is the use of Xticks () and Yticks () in plotting?

The xticks() and yticks() function takes a list object as argument. The elements in the list denote the positions on corresponding action where ticks will be displayed. This method will mark the data points at the given positions with ticks.


1 Answers

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'.

like image 101
Serenity Avatar answered Sep 18 '22 23:09

Serenity