Fontsize in xticks not responding correctly

27 Views Asked by At

I am trying to change the fontsize of xticks and yticks in python. The plot represents daily averages for a random location for December 2019.

My problem is that I sent set yticks fontsize to 26 but only the label od Dec2019 changes but not the numbers in xticks.

enter image description here

Here is the essential part of the code: Here is the part of the code final = reduce(lambda left,right: pd.merge(left,right, left_index=True, right_index=True), dfs_filtered)

final.resample('D').mean().plot( figsize=(12,9),marker='.'); plt.legend(etik,fontsize=13)
plt.ylabel('Daily mean concentration $(μg/m^3)$',fontsize=13); plt.xlabel('Day',fontsize=13)
plt.xlim(pd.Timestamp('2019-12-01'),pd.Timestamp('2019-12-31'))

plt.xticks(fontsize=26); plt.yticks(fontsize=26)

plt.ylim(bottom=0); plt.margins(x=0)
plt.title(list(aerosols.keys())[n]+' ('+ABBR[list(aerosols.keys())[n]]+')',fontsize=13)

plt.show()

Explanation: The problem was the existence of label Dec2019. This label was considered by python as major, downgrading the 02,09,16,23,30 to minor. In y axis, there was not a problem as 2,4,6,8,10 were considered as major. Also, the proposed question does not answer to my question, although I used parts of code from the proposed one.

1

There are 1 best solutions below

0
Dimitris Tsiaousidis On

using the answer @Bill Huang proposed, it seems that the xticks were considered by Python as minor, while the label Dec 2019 and yticks as major.

fig, ax = plt.subplots()
ax.tick_params(axis='both', which='major', labelsize=26)
ax.tick_params(axis='both', which='minor', labelsize=26)

final.resample('D').mean().plot( figsize=(12,9),ax=ax,marker='.'); plt.legend(etik,fontsize=13)
plt.ylabel('Daily mean concentration $(μg/m^3)$',fontsize=13); plt.xlabel('Day',fontsize=13)
plt.xlim(pd.Timestamp('2019-12-01'),pd.Timestamp('2019-12-31'))

plt.ylim(bottom=0); plt.margins(x=0)
plt.title(list(aerosols.keys())[n]+' ('+ABBR[list(aerosols.keys())[n]]+')',fontsize=13)

plt.show()