{ "metadata": { "name": "", "signature": "sha256:9991874e77a8ce753c37ea79f1f7d8b4dfed66d5924ad1d776be24afaad6c979" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "-- **Adam Hughes** \n", "\n", "-- **2 / 27 / 2014** \n", "\n", "-- **The George Washington University** " ] }, { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Configuration for notebook style" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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.\n", "\n", "Figure style should be updated later based on Damon McDougall's blog to reflect journal latex templates (see **Related**)." ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Globals for quicker tweaking" ] }, { "cell_type": "code", "collapsed": false, "input": [ "JOURNAL_TEXT = 9\n", "\n", "# Plotting\n", "LABELSIZE = JOURNAL_TEXT +1 #All plot text except legends (recommed JT -1)\n", "LEGENDSIZE = LABELSIZE * 1.2\n", "\n", "# Notebook Style (pyparty style, path or url to .css or None)\n", "NBSTYLE = 'gwu' \n", "\n", "# Logging\n", "HIDE_LOG = True" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Pylab (numpy, inline plotting)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "%pylab inline" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "prompt_number": 2 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Load common pyparty imports" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from __future__ import division\n", "from pyparty import Canvas, splot, showim" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Set notebook style from pyparty.bundled function" ] }, { "cell_type": "code", "collapsed": false, "input": [ "if NBSTYLE:\n", " from pyparty.bundled import load_style\n", " load_style(NBSTYLE);" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "display_data", "text": [ "" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Matplotlib Style settings" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can find the matplotlibrc file path via:\n", "\n", ".. >>> matplotlib.matplotlib_fname()\n", "\n", "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...\n", "\n", "**Caveats:**\n", "- text.usetex=True requires dvipng and Ghostscript\n", " - sudo apt-get install dvipng && sudo apt-get install ghostscript\n", " - Tex is still rendered, just sized unsually if usetex=False" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from matplotlib import rcParams\n", "\n", "# # Figure/lines\n", "rcParams['figure.figsize'] = (7.3, 4.2) # SET THIS BASED ON LATEX CONSDIERATIONS LATER!\n", "rcParams['lines.linewidth'] = 2.0\n", "#rcParams['figure.facecolor'] = '0.7' #Plot border, doesn't work\n", "\n", "# Plot itself\n", "#rcParams['axes.facecolor'] = '0.75' # Gray background\n", "\n", "# # Labels\n", "rcParams['axes.labelsize'] = LABELSIZE\n", "rcParams['xtick.labelsize'] = LABELSIZE\n", "rcParams['ytick.labelsize'] = LABELSIZE\n", "\n", "# # Colors\n", "#rcParams['axes.facecolor'] = (1,0,0) #Same as ipython notebook\n", "\n", "# # Legend\n", "rcParams['legend.loc'] = 'upper right'\n", "rcParams['legend.fontsize'] = LEGENDSIZE\n", "rcParams['legend.fancybox'] = True\n", "rcParams['legend.scatterpoints'] = 1 # Draw one scatter point in legend \n", "rcParams['legend.markerscale'] = 1.5 # But make it large\n", "\n", "# # Font and text\n", "rcParams['font.family'] = 'serif'\n", "rcParams['font.serif'] = ['Computer Modern'] # Also used by latex (this is default already)\n", "#rcParams['font.weight'] = 'bold' # These don't work\n", "#rcParams['font.style'] = 'oblique'\n", "rcParams['font.size'] = LABELSIZE #Matplotlib title, labels\n", "\n", "# Text and latex\n", "rcParams['text.usetex'] = False # Slight differce in how math symbols; as well as text labeled\n", "rcParams['text.color'] = 'black'\n", "\n", "# # Image\n", "rcParams['image.cmap'] = 'gray' #Default colormap for 1-channel images\n", "\n", "# #Saving\n", "rcParams['savefig.dpi'] = 200\n", "rcParams['savefig.format'] = 'png'\n", "rcParams['savefig.bbox'] = 'tight' #or standard" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Set default plotting fig size and backend to SVG." ] }, { "cell_type": "code", "collapsed": false, "input": [ "%config InlineBackend.figure_format = 'svg'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "ERROR: global name 'select_figure_formats' is not defined\n" ] } ], "prompt_number": 6 }, { "cell_type": "heading", "level": 4, "metadata": {}, "source": [ "Supress warning from logging in most places" ] }, { "cell_type": "code", "collapsed": false, "input": [ "if HIDE_LOG:\n", " import warnings #supress non-pyparty log msgs\n", " warnings.filterwarnings('ignore') " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Related" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Damon McDougall's**: [Publication-ready the first time: Beautiful, reproducible plots with Matplotlib](http://damon-is-a-geek.com/publication-ready-the-first-time-beautiful-reproducible-plots-with-matplotlib.html)\n", "- **Louic's Weblog**: [IPython Notebook Custom CSS](http://blog.louic.nl/?p=683)\n", "- **Sandro Tosi**: [Matplotlib for Python Developers: Build Remarkable Publication Quality Plots...](http://books.google.com/books?id=4wMn27KSnTsC&pg=PA101&lpg=PA101&dq=matplotlibrc+font+name+example&source=bl&ots=ZeCABiOv8X&sig=Wsho_P0Nk18LRlzuDQddkJyNiF8&hl=en&sa=X&ei=oNEPU5GYHeHc0QGm7YGQBg&ved=0CDcQ6AEwAjgK#v=onepage&q=matplotlibrc%20font%20name%20example&f=false)" ] } ], "metadata": {} } ] }