2010-05-18 47 views
1

我有我的第一次嘗試使用matplotlib和scipy來做我的數據的一些散點圖(太多變量,試圖一次看到許多事情)的一些問題。下面是我的一些代碼,工作相當好...麻煩在Matplotlib/Scipy等使用膠乳

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() 

我試圖修改代碼,包括乳膠字體和解釋,沒有它似乎爲我工作,但是。這裏有一個例子嘗試,沒有工作:

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() 

我使用Fink安裝python26與SciPy的matplotlib等相應的包我一直在使用IPython的和人工的工作,而不是在Python腳本。

由於我對python和scipy完全陌生,所以我確信我正在犯一些愚蠢的簡單錯誤。請賜教!我非常感謝幫助!

回答

0

代碼對我來說看起來不錯,特別是rc命令。

查看本頁:Text Rendering with LaTeX。確保安裝了LaTeX,dvipng和ghostscript。同時檢查你正在使用的後端;你的可能不支持LaTeX。

+0

史蒂夫!感謝您的評論,我感謝您對此的看法。我正在運行基於--verbose-helpful標誌的MacOSX後端(版本未知)。 更多信息 - matplotlib 0.99.0(fink上可用) tzinfo.py提供了一個棄用警告,因爲我相信即將發佈的py30版本。 – AllenH 2010-05-18 17:56:48

+0

順便說一句,我應該提到我得到更簡單的情節乳膠輸出的實例,所以我試圖以這種方式追蹤它。由於某種原因,上面的代碼甚至不會輸出正常的散點圖 - 所以有些線路正在越過某處 - 我懷疑我使用python/scipy是不正確的。 – AllenH 2010-05-18 17:57:54

2

對於那些剛剛開始SciPy的/ matplotlib,我發現這是很有幫助的尋找我的安裝信息,因爲我目前使用它......從這個link

創建一個名爲simple_plot.py這包括最小腳本:

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

然後運行在命令行以下操作:

python simple_plot.py --verbose-helpful 

我接收到的結果是:

$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 

我希望這可以幫助剛剛開始像我一樣的人! :)感謝大家對此的看法!