Recommended Setting Changes for Python Graphs

The beautiful thing about matplotlib is that it is infinitely customizable and has great default settings. However, it is worth looking at the matplotlibrc file to change some of the default settings. The file is heavily and wonderfully annotated, so you know exactly what you’re changing as you do it. I played around with it a bit and settled on what I like as my new default settings. I mostly changed text sizes and the widths of the axes (which I felt were too thin).

Here’s what I recommend:

  1. figure.figsize   : 6.5, 5.5    – I like the figure size of 6.5 x 5.5. I don’t know why. It’s a holdover from how I made R graphs and I’ve gotten used to it
  2. legend.numpoints     : 1    – get rid of the double points in pylab’s legend. I have no idea why the default is 2. It always looked funny.
  3. legend.fontsize      : 12 – reduces the legend font size. I found that the legend was taking up most of my plot
  4. legend.handletextpad : 0.2 – reduce the white space between legend points and legend text

  5. ytick.major.width : 1 – increase the thickness of the tick lines
    ytick.minor.width : 1 – same as above
  6. xtick.major.width : 1 -again
    xtick.minor.width : 1
  7. axes.axisbelow      : True – puts the grid BELOW the elements (rather than overtop of them)
  8. axes.linewidth      : 1.5    – gives the axes a thicker line. I think this makes the graph pop a little more

If you save images as PNG or JPG, it’s also worth changing the DPI to something higher (the default is 50). Since I use PDF, this isn’t really an issue.

Here’s the final result:


Now, if only I could get the TeX font not to look ugly as sin and figure out how to make minor ticks turn on by default..


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s