Wednesday 24 July 2013

Spacing in ipython notebook subplots and default settings.

Spacing:
import matplotlib as m

m.rcParams['figure.subplot.hspace'] = 0.4 # 0.3 default.
m.rcParams['figure.subplot.wspace'] = 0.3 # 0.2 default.



Defaults:

At the start of each script use,

import ipythonNotebookConfig

where, ipythonNotebookConfig.py  contains:

import matplotlib as m
print 'The matplotlib rc file is', m.matplotlib_fname()


# Set default svg:  publish quality images.
from IPython.zmq.pylab import backend_inline
cfg = backend_inline.InlineBackendConfig.instance()
cfg.figure_format = 'svg' # 'png' / 'svg'



# Control saving:  keep the nice images for .pdf inclusion.
from IPython.zmq.pylab.backend_inline import InlineBackendConfig
InlineBackendConfig.instance().figure_format = 'svg'



print m.rcParams['figure.


# print m.rcParams['figure.figsize'] # default plot size
# m.rcParams['figure.figsize'] = (11, 7.7) # double it
# print m.rcParams['lines.linewidth'] # this gives 2 though I set 1.
m.rcParams['lines.linewidth'] = (1) # half it
#m.rcParams['savefig.dpi'] = 80 # changes displayed figure size
m.rcParams['axes.grid'] = True

scale=1
m.rcParams['legend.fontsize'] = 10/scale
m.rcParams['axes.labelsize'] = 12/scale
m.rcParams['figure.figsize'] = (12/scale, 8/scale)
m.rcParams['font.size'] = 10/scale # numbers
m.rcParams['legend.fontsize'] = 10/scale # numbers

# Affects all scaling.  Set scale linearly with this value.  80 looks good onscreen.
m.rcParams['savefig.dpi'] = 80 

m.rcParams['grid.linewidth'] = 0.5/scale
m.rcParams['lines.linewidth'] = 0.5/scale # data lines

# matplotlib.rcParams['legend.frameon'] = False
# Doing this screws the plot size, after I updated.

m.rcParams['axes.titlesize'] = 12./scale
m.rcParams['axes.titlesize'] = 12./scale

m.rcParams['grid.linestyle'] = '-'
m.rcParams['grid.color'] = '0.85'

# These prevent two line titles and axis labels overlapping.
m.rcParams['figure.subplot.hspace'] = 0.4 # 0.3 default.
m.rcParams['figure.subplot.wspace'] = 0.3 # 0.2 default.

# experimental from 
# http://nerdjusttyped.blogspot.co.uk/2010/07/type-1-fonts-and-matplotlib-figures.html
# This causes, `type 1 fonts' instead of the default type 3.
# Really, I'm trying to change from .png to .pdf plots.
m.rcParams['ps.useafm'] = True
m.rcParams['pdf.use14corefonts'] = True
m.rcParams['text.usetex'] = True

No comments:

Post a Comment