Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created June 16, 2011 14:47
Show Gist options
  • Save davidandrzej/1029378 to your computer and use it in GitHub Desktop.
Save davidandrzej/1029378 to your computer and use it in GitHub Desktop.
Print-friendly plot with Matplotlib
"""
Handful of tricks for making a print-friendly plot
David Andrzejewski
"""
import matplotlib as MPL
import matplotlib.pyplot as P
# Have plots be the exact same size
MPL.rc('figure', figsize=(14, 11)) # figure size in inches
# LaTeX captions/labels
MPL.rc('font',**{'family':'serif','serif':['Times']})
MPL.rc('text', usetex=True)
# Fake data
prev_y = [0, 0.2, 0.5, 0.7, 1]
prev_x = [0, 0.1, 0.4, 0.6, 1]
our_y = [0, 0.3, 0.6, 0.7, 0.8, 1]
our_x = [0, 0.05, 0.25, 0.4, 0.55, 1]
# Make plots
P.figure()
P.plot(prev_x, prev_y, 'k--', linewidth=5,
label='Previous approach')
P.plot(our_x, our_y, 'k-', linewidth=5,
label='Our approach')
# Customize axis ticks
P.xticks(fontsize=50)
P.yticks(fontsize=50)
P.gca().xaxis.set_major_locator(MPL.ticker.FixedLocator([1.0]))
P.gca().yaxis.set_major_locator(MPL.ticker.FixedLocator([0.0, 1.0]))
P.gca().set_xticklabels(["1.0"])
P.gca().set_yticklabels(["0.0","1.0"])
# LaTeX-ified axis labels
P.ylabel('Good $\gamma$', fontsize=50)
P.xlabel('Bad $\Sigma$', fontsize=50)
P.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment