I'm trying to plot a figure by pandas.
The font of other text could be set.
But xlabel couldn't be set. ax3 couldn't use axes.set_xlabel() parameter.
I also try ax.set_fontsize() or plt.rcParams.update({'font.size': 22}). It doesn't work.
plt.figure()
ax1 = df_plot.plot(x='wind_direct',y=plot_columns,figsize=(30,18),linewidth=5,kind='line',legend=True, fontsize=16)
ax1.legend(loc=2,fontsize=20)
ax1.set_ylabel('kw',fontdict={'fontsize':24})
ax2 = ax1.twinx()
ax3 = df_plot.plot(x='wind_direct',y=counts_columns,figsize=(30,18),kind='bar',legend=True, ax=ax2, fontsize=16)
ax3.set_title(title,pad=20, fontdict={'fontsize':24})
ax3.set_ylabel('counts',fontdict={'fontsize':24})
#ax3.set_fontsize(24)
plt.rcParams.update({'font.size': 22})
ax3.legend(loc=1,fontsize=20);
The size of a plot can be modified by passing required dimensions as a tuple to the figsize parameter of the plot() method. it is used to determine the size of a figure object.
If we want to change the font size of the axis labels, we can use the parameter “fontsize” and set it your desired number.
plt.figure() The parameter 'plt.rcParams.update({'font.size': 36})' must set in the top.
like this:
plt.figure()
plt.rcParams.update({'font.size': 22}) # must set in top
ax1 = df_plot.plot(x='wind_direct',y=plot_columns,figsize=(30,18),linewidth=5,kind='line',legend=True, fontsize=16)
ax1.legend(loc=2,fontsize=20)
ax1.set_ylabel('kw',fontdict={'fontsize':24})
ax2 = ax1.twinx()
ax3 = df_plot.plot(x='wind_direct',y=counts_columns,figsize=(30,18),kind='bar',legend=True, ax=ax2, fontsize=16)
ax3.set_title(title,pad=20, fontdict={'fontsize':24})
ax3.set_ylabel('counts',fontdict={'fontsize':24})
ax3.legend(loc=1,fontsize=20);
Because the 'plt.rcParams' is the default value.
The xlabel font maybe use 'plt.rcParams' when pandas.DataFrame.axes is bulit.
So 'plt.rcParams' should set in front of pandas.DataFrame.axes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With