Matplotlib

Plotting

http://www.scipy.org/Plotting_Tutorial

http://www.scienceblogs.de/diaxs-rake/2009/04/wissenschaftliches-arbeiten-mit-python-und-pylab-ii-bunte-bildchen-mit-matplotlib.php

http://www.physics.nmt.edu/~raymond/software/python_notes/paper004.html

http://www.packtpub.com/article/advanced-matplotlib-part2

References and further information

A good reference for all the rc-options is here: http://matplotlib.sourceforge.net/users/customizing.html

High-Quality Plots

LaTeX rendering

http://www.scipy.org/Cookbook/Matplotlib/UsingTex

http://matplotlib.sourceforge.net/users/usetex.html

Using LaTeX in matplotlib: http://www.scipy.org/Cookbook/Matplotlib/LaTeX_Examples

The LaTeX temporary files are stored at ~/.matplotlib/tex.cache.

Matplotlib/Latex http://mike.depalatis.net/docs/mpllatex.html, http://code.google.com/p/mplrc/

LaTeX rendering can be activated using

import matplotlib
#matplotlib.use(‘GTK’)
matplotlib.use(‘Pdf’)
# Before pylab!
from matplotlib import rc
rc(‘text’, usetex=True)

it does not seem to work with the GTK backend, I obtain an error.

Change the power limit for scientific notation

#axes.formatter.limits : -7, 7 # use scientific notation if log10
                               # of the axis range is smaller than the
                               # first or larger than the second
rcParams['axes.formatter.limits'] = (-1,1)

This also affects the labels on the colorbar.

Manual Hacks:

This can be done using the parameter text.latex.preamble

Publication quality settings

Example settings used for plots  http://mike.depalatis.net/docs/mpllatex.html

Changing the layout for certain journals: http://code.google.com/p/mplrc/

Size of Colorbar

The height, width, etc. of the colorbar can be adjusted using the keywords

shrink, fraction, aspect, pad, orientation

see http://matplotlib.sourceforge.net/api/colorbar_api.html

Specific Labels (pi,…) (2011-06-26)

http://128.250.32.118:8371/posts/tweak_labels_and_ticks_in_2d_plots_using_matplotlib/ axes.set_xticks([float((j-1/3)*np.pi) for j in range(0,3)]) axes.set_xticklabels(['$-\pi/3$', '$2\pi/3$', '$5\pi/3$'])

Thickness of line around plot

rcParams[‘axes.linewidth’] = 0.7

Minor Ticks in Log Plot

http://www.ianhuston.net/2011/02/minor-tick-labels-in-matplotlib

Padding between the axes and the labels (2011-06-27)

ax.xaxis.labelpad = 20 

http://stackoverflow.com/questions/6406368/matplotlib-move-x-axis-label-downwards-but-not-x-axis-ticks

Tick label orientation an vertical position (2011-07-12)

This can be done using

for label in ax.get_xticklabels():
label.set_verticalalignment(‘center’)

http://old.nabble.com/centering-axis-ticks-labels-td24411951.html

Bold Ticks

http://old.nabble.com/Bold-Latex-Tick-Labels-td28037900.html

Multiple Axes

http://stackoverflow.com/questions/647443/multiple-overlapping-plots-with-independent-scaling-in-matplotlib

Backend selection

http://stackoverflow.com/questions/4930524/how-to-set-backend-in-matplotlib-in-python

Logarithmic axes

http://stackoverflow.com/questions/773814/plot-logarithmic-axes-with-matplotlib-in-python

Saving Figures to pdfs

http://matplotlib.sourceforge.net/faq/howto_faq.html

Subplot adjustment and size

atplotlib.pyplot.subplots_adjust see http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.subplots_adjust

Matplotlib AxesGrid Toolkit    http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/

Contour Plots

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.contourf

http://www.pyngl.ucar.edu/Tutorial/ngl02p.shtml

http://matplotlib.sourceforge.net/examples/pylab_examples/griddata_demo.html

http://tug.org/PSTricks/main.cgi?file=pst-plot/3D/contour

http://bulldog2.redlands.edu/facultyfolder/deweerd/tutorials/Tutorial-ContourPlot.pdf

http://grantingram.wordpress.com/plotting-2d-unstructured-data-using-free-software/

Logarithmic color bar: http://adversus.110mb.com/?cat=8, http://old.nabble.com/logarithmic-scale-of-colorbar-with-ticks-and-custom-labels-td23426338.html

HexBins: http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set

3D-Histograms

http://toeholds.wordpress.com/2010/03/26/3d-bar-histogram-in-python/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: