在matplotlib图中设置字体大小

时间:2016-10-11 07:15:08

标签: python matplotlib

在下面的代码中,如何使x轴和图例看起来清晰可辨?

rcParams['xtick.labelsize'] = 5
rcParams['ytick.labelsize'] = 5
rcParams['legend.fontsize'] = 5

ax[idx/3, idx%3].xaxis.set_major_formatter(DateFormatter('%Y'))
ax[idx/3, idx%3].xaxis.set_minor_formatter(DateFormatter('\n%b'))
ax[idx/3, idx%3].xaxis.set_major_locator(YearLocator())
ax[idx/3, idx%3].xaxis.set_minor_locator(MonthLocator(bymonthday=1, interval=2))
#ax[idx/3, idx%3].yaxis.set_major_locator(MaxNLocator(5))
#ax[idx/3, idx%3].yaxis.set_minor_locator(MaxNLocator(25))

# Create nice-looking grid for ease of visualization
ax[idx/3, idx%3].grid(which='major', alpha=0.5)

plt.title(names_cols[idx])

# Create a legend with transparent box around it
leg = plt.legend(loc='best', fancybox=None, prop={'size': 'x-small'})
leg.get_frame().set_linewidth(0.0)
leg.get_frame().set_alpha(0.5)

enter image description here

0 个答案:

没有答案