-- **Adam Hughes**

-- **2 / 27 / 2014**

-- **The George Washington University**

Configuration for notebook style

This notebook is intended to be run by other notebooks through the %run ipython magic. The running notebook will then be styled nicely, have the most common pyparty imports, have pre-set figure size and plotting backend (svg), and will suppress logging in certain cases.

Figure style should be updated later based on Damon McDougall's blog to reflect journal latex templates (see Related).

Globals for quicker tweaking


In [2]:
JOURNAL_TEXT = 9

# Plotting
LABELSIZE = JOURNAL_TEXT +1 #All plot text except legends (recommed JT -1)
LEGENDSIZE = LABELSIZE * 1.2

# Notebook Style (pyparty style, path or url to .css or None)
NBSTYLE = 'gwu'  

# Logging
HIDE_LOG = True

Load common pyparty imports


In [3]:
from __future__ import division
from pyparty import Canvas, splot, showim

Set notebook style from pyparty.bundled function


In [4]:
if NBSTYLE:
    from pyparty.bundled import load_style
    load_style(NBSTYLE);


Matplotlib Style settings

You can find the matplotlibrc file path via:

.. >>> matplotlib.matplotlib_fname()

The computer modern font setting is default, so I am happy with it; however, changing the font as done in the commented block below seems to be buggy in the notebook. I can't change the font or its weight, but the size does seem to change correctly...

Caveats:

  • text.usetex=True requires dvipng and Ghostscript
    • sudo apt-get install dvipng && sudo apt-get install ghostscript
    • Tex is still rendered, just sized unsually if usetex=False

In [8]:
from matplotlib import rcParams

# # Figure/lines
rcParams['figure.figsize'] = (10, 6) # SET THIS BASED ON LATEX CONSDIERATIONS LATER!
#rcParams['figure.facecolor'] = '(1,0,0)'
rcParams['lines.linewidth'] = 2.0

# # Labels
rcParams['axes.labelsize'] = LABELSIZE
rcParams['xtick.labelsize'] = LABELSIZE
rcParams['ytick.labelsize'] = LABELSIZE

# # Legend
rcParams['legend.loc'] = 'upper right'
rcParams['legend.fontsize'] = LEGENDSIZE
rcParams['legend.fancybox'] = True
rcParams['legend.scatterpoints'] = 1  # Draw one scatter point in legend   
rcParams['legend.markerscale'] = 1.5 # But make it large

# # Font and text
rcParams['font.family'] = 'serif'
rcParams['font.serif'] = ['Computer Modern']  # Also used by latex (this is default already)
#rcParams['font.weight'] = 'bold'  # These don't work
#rcParams['font.style'] = 'oblique'
rcParams['font.size'] = LABELSIZE     #Matplotlib title, labels

# Text and latex
rcParams['text.usetex'] = True  # Slight differce in how math symbols; as well as text labeled
rcParams['text.color'] = 'black'

# # Image
rcParams['image.cmap'] = 'gray'  #Default colormap for 1-channel images

# #Saving
rcParams['savefig.dpi'] = 200
rcParams['savefig.format'] = 'png'
rcParams['savefig.bbox'] = 'tight' #or standard

Set default plotting fig size and backend to SVG.


In [6]:
%config InlineBackend.figure_format = 'svg'


ERROR: global name 'select_figure_formats' is not defined

Supress warning from logging in most places


In [7]:
if HIDE_LOG:
    import warnings #supress non-pyparty log msgs
    warnings.filterwarnings('ignore')