views:

233

answers:

2

I'm having some issues with my first attempts at using matplotlib and scipy to make some scatter plots of my data (too many variables, trying to see many things at once). Here's some code of mine that is working fairly well...

import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py

FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel('Cu / III')
ax.set_ylabel('Growth T')
ax.grid(True)
pylab.show()

I tried to change the code to include latex fonts and interpreting, none of it seems to work for me, however. Here's an example attempt that didn't work:

import numpy
from scipy import *
import pylab
from matplotlib import *
import h5py

rc('text', usetex=True)
rc('font', family='serif')

FileID = h5py.File('3DiPVDplot1.mat','r')
# (to view the contents of: list(FileID) )
group = FileID['/']
CurrentsArray = group['Currents'].value
IvIIIarray = group['IvIII'].value
PFarray = group['PF'].value
growthTarray = group['growthT'].value
fig = pylab.figure()
ax = fig.add_subplot(111)
cax = ax.scatter(IvIIIarray, growthTarray, PFarray, CurrentsArray, alpha=0.75)
cbar = fig.colorbar(cax)
ax.set_xlabel(r'Cu / III')
ax.set_ylabel(r'Growth T')
ax.grid(True)
pylab.show()

I'm using fink installed python26 with corresponding packages for scipy matplotlib etc. I've been using iPython and manual work instead of scripts in python.

Since I'm completely new to python and scipy, I'm sure I'm making some stupid simple mistakes. Please enlighten me! I greatly appreciate the help!

A: 

The code looks okay to me, particularly the rc commands.

Check this page: Text Rendering with LaTeX. Make sure that LaTeX, dvipng, and ghostscript are installed. Also check which backend you are using; yours may not support LaTeX.

Steve
Hi Steve! Thanks for your comments, I appreciate your thoughts on this. I'm running the MacOSX backend (version unknown) based upon the --verbose-helpful flag.more info- matplotlib 0.99.0 (available on fink)tzinfo.py gives a deprecation warning due to the upcoming py30 release I believe.
AllenH
BTW, I should mention I do get instances of latex output with simpler plots, so I'm attempting to track it down in that manner. For some reason the above code doesn't output even the normal scatter graph- so some wires are getting crossed somewhere- I suspect my use of python/scipy is incorrect.
AllenH
+2  A: 

For those of you just starting scipy/matplotlib, I found this helpful in finding info about my installation as I'm currently using it... from this link:

Create a file called simple_plot.py which includes the minimal script:

from pylab import *
plot([1,2,3])
show()

then run the following at the command line:

python simple_plot.py --verbose-helpful

The result I received was:

$HOME=/Users/me
CONFIGDIR=/Users/me/.matplotlib
matplotlib data path /sw/lib/python2.6/site-packages/matplotlib/mpl-data
loaded rc file /sw/lib/python2.6/site-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 0.99.0
verbose.level helpful
interactive is False
units is False
platform is darwin
Using fontManager instance from /Users/me/.matplotlib/fontList.cache
/sw/lib/python2.6/site-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated
  from sets import Set
backend MacOSX version unknown

I hope this helps someone just starting out like me! :) Thanks for everyone's thoughts on this!

AllenH