-1

I was just wondering how can I increase the fontsize of x-axis and y-axis labels for subplots in matplotlib. I have plotted six subplots and have managed to increase their figuresize but was just wondering how can I increase the fontsize of x and y axis labels for my plots. I have searched the stackoverflow but could not find any valuable solution. The code for the plots is as follows:

fig,axes = plt.subplots(2,3,figsize=(30,30))
sns.barplot(ax=axes[0,0],y=df["Education"],x=df["MntWines"],data=df)
sns.barplot(ax=axes[0,1],y=df["Education"],x=df["MntFruits"],data=df)
sns.barplot(ax=axes[0,2],y=df["Education"],x=df["MntMeatProducts"],data=df)
sns.barplot(ax=axes[1,0],y=df["Education"],x=df["MntFishProducts"],data=df)
sns.barplot(ax=axes[1,1],y=df["Education"],x=df["MntSweetProducts"],data=df)
sns.barplot(ax=axes[1,2],y=df["Education"],x=df["MntGoldProds"],data=df)
plt.tight_layout()
plt.show()

The output figure is as follows: enter image description here

Any lead to do this would be appreciated. Thanks!

Sam
  • 65
  • 2
  • 9

2 Answers2

2

You can change the font size with the following:

import matplotlib.pyplot as plt

plt.rc('font', size=10) #controls default text size
plt.rc('axes', titlesize=10) #fontsize of the title
plt.rc('axes', labelsize=10) #fontsize of the x and y labels
plt.rc('xtick', labelsize=10) #fontsize of the x tick labels
plt.rc('ytick', labelsize=10) #fontsize of the y tick labels
plt.rc('legend', fontsize=10) #fontsize of the legend
alec_djinn
  • 10,104
  • 8
  • 46
  • 71
1

You should be able to update the label size globally via this line:

from matplotlib import pyplot as plt
plt.rcParams.update({'axes.labelsize': 'large'})

See https://matplotlib.org/stable/tutorials/introductory/customizing.html