Skip to content

Instantly share code, notes, and snippets.

@mfouesneau
Last active August 29, 2015 14:07
Show Gist options
  • Save mfouesneau/c6d27990ba57dabcd9fd to your computer and use it in GitHub Desktop.
Save mfouesneau/c6d27990ba57dabcd9fd to your computer and use it in GitHub Desktop.
ezrc mpl rc update quickly
def ezrc(fontSize=22., lineWidth=2., labelSize=None, tickmajorsize=10,
tickminorsize=5, figsize=(8, 6)):
"""
Define params to make pretty fig for slides and papers
"""
from pylab import rc, rcParams
if labelSize is None:
labelSize = fontSize + 5
rc('figure', figsize=figsize)
rc('lines', linewidth=lineWidth)
rcParams['grid.linewidth'] = lineWidth
rcParams['font.sans-serif'] = ['Helvetica']
rcParams['font.serif'] = ['Helvetica']
rcParams['font.family'] = ['Times New Roman']
rc('font', size=fontSize, family='serif', weight='bold')
rc('axes', linewidth=lineWidth, labelsize=labelSize)
rc('legend', borderpad=0.1, markerscale=1., fancybox=False)
rc('text', usetex=True)
rc('image', aspect='auto')
rc('ps', useafm=True, fonttype=3)
rcParams['xtick.major.size'] = tickmajorsize
rcParams['xtick.minor.size'] = tickminorsize
rcParams['ytick.major.size'] = tickmajorsize
rcParams['ytick.minor.size'] = tickminorsize
rcParams['text.latex.preamble'] = ["\\usepackage{amsmath}"]
@yoachim
Copy link

yoachim commented Oct 9, 2014

So I assume you would use it thusly:

x = np.arange(100.)/99.*4.*np.pi
y = np.sin(x)

ezrc()
fig = plt.plot(x,y)
plt.savefig('paper.pdf')
fig.close()

ezrc(fontSize=34, lineWidth=8)
fig = plt.plot(x,y)
plt.savefig('slide.pdf')

Is there a way to change the rcParams and then force figures to update? So then you could do:

x = np.arange(100.)/99.*4.*np.pi
y = np.sin(x)

fig = plt.plot(x,y)
ezrc()
plt.savefig('paper.pdf')
ezrc(fontSize=34, lineWidth=8)
plt.savefig('slide.pdf')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment