Quick reference for common matplotlib commands

Labels and so on

   1 ax1.tick_params(axis='both', which='major', labelsize=6)
   2 ax2.tick_params(axis='both', which='major', labelsize=6)

Font sizes

   1 # Font properties
   2         from matplotlib.font_manager import FontProperties
   3         font = FontProperties()
   4         font.set_family('serif')
   5 
   6         ax1.set_ylabel('Unweighted', fontsize=8, fontproperties=font)

Multiple plots

Separate plots with shared axis limits

   1         ax1 = fig.add_subplot(2, 1, 1)
   2         ax2 = fig.add_subplot(2, 1, 2, sharex=ax1)
   3         from matplotlib.artist import setp
   4         setp(ax1.get_xticklabels(), visible=False)

Date axes

   1 adf = ax2.xaxis.get_major_formatter()
   2 adf.scaled[1./(24*60)] = '%H:%M'  # set the < 1d scale to H:M                                      
   3 adf.scaled[1./24] = '%H:%M'  # set the < 1d scale to H:M                                           
   4 adf.scaled[1.0] = '%m-%d' # set the > 1d < 1m scale to Y-m-d                                       
   5 adf.scaled[30.] = '%Y-%m' # set the > 1m < 1Y scale to Y-m                                         
   6 adf.scaled[365.] = '%Y' # set the > 1y scale to Y                                                  

DebianNotes/matplotlib (last edited 2015-06-26 09:54:52 by RichardDarst)