Posts Tagged ‘pylab’

Errorbars in matplotlib

Sunday, January 27th, 2008

Here’s how to plot x or y errorbars (or both) and how to customize the resulting plot.
(more…)

Adjust settings for matplotlib using rc and matplotlibrc

Monday, January 21st, 2008

The matplotlibrc file contains many useful parameters for tweaking your setup to your liking, and it’s worth at least skimming through to get an idea of what it contains. Editing the file makes more permanent changes, while using the pylab rcParams dictionary or rc() and rcdefaults() functions lets you make and revert changes on the fly.

View the rc parameters by using

import pylab as p
print p.rcParams

Examples ensue.
(more…)

Change distance of tick labels from axis

Thursday, January 17th, 2008

Set the rc parameters using the rc function.


import pylab as p
p.rc(('xtick.major','xtick.minor','ytick.major','ytick.minor'), pad=10)
p.plot([1,2,3])

If you only want to change one of the tick labels, say, the x major ticks, use
p.rc(’xtick.major), pad=10)

When you’re done and want to reset the rc settings, use

p.rcdefaults()

See matplotlibrc for more settings you can change via the rc command.

Create a second y-axis in matplotlib

Sunday, December 2nd, 2007

Today I was trying to figure out how to plot two time series with differently scaled values. I found two_scales.py example in the matplotlib examples which describes how to do it.

Here’s a slightly simplified version of the code, and afterward a detailed explanation of what’s going on. (more…)

Creating a custom bar plot in matplotlib

Saturday, November 3rd, 2007

Bar plots are one of the simplest kinds of plots, but for some reason in many programs it’s difficult to get the labels you want, correct error bars, and control over every aspect of the plot. Here’s how to create a custom bar plot using the Python plotting module matplotlib. (more…)