0

In the code below, how do I make the x-axis and legend look legible?

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

user308827
  • 21,227
  • 87
  • 254
  • 417
  • The problem is that you have too many ticks on the x axis and they overlap. Since you're cramming so many plots together, you could try [vertical x labels](http://matplotlib.org/examples/ticks_and_spines/ticklabels_demo_rotation.html)? I don't know if that will then cause new problems. – roganjosh Oct 11 '16 at 07:45
  • A good way to reduce the number of tick labels while keeping the number of ticks constant is the use of minor ticks. For example you could make the beginning of each quarter (Jan/Apr/Jul/Oct) major ticks and all other months minor ticks. Have a look at this example: http://matplotlib.org/examples/pylab_examples/major_minor_demo1.html – Sven Rusch Oct 11 '16 at 08:31

0 Answers0