Monday, December 14, 2009

Matplotlib in OS X (2)


Now that I have a working intall of matplotlib, I'm going to explore its capabilities to replace R, at least for plotting stuff. The more heavy duty components of R will still be irreplaceable.

The matplotlib example for histograms is here. It's not very intuitive, at least at first sight. I took nearly everything in the example code and wrapped it in a function with a silly name and placed it in a module called H. If you want to follow this example it should be simple to figure out what I did.

[UPDATE: Although this works well, and is said to be more efficient, there is a simpler API. See example here]

The script that connects my data with the plot code is just a couple of lines:

import random
from random import gauss
import matplotlib.pyplot as plt
from H import doWeirdStuffToMakeAHistogram

random.seed(133)
mu = 10
sigma = 3
L = [gauss(mu,sigma) for i in range(1000)]
doWeirdStuffToMakeAHistogram(
L,bins=40,x0=0,x1=20,col='blue')
plt.savefig('example.pdf')

No comments: