2012-10-30 3 views
2

rootpy와 matplotlib로 ROOT 2D 히스토그램을 플롯하려고합니다.rootpy와 matplotlib로 2D 히스토그램의 플롯

그러나
from rootpy.io import File 
from rootpy.plotting import Hist 
import rootpy.plotting.root2matplotlib as rplt 
import matplotlib.pyplot as plt 
inputFile = File('mydata.root', 'read') 
h_response = inputFile.myfolder.response 

plt.figure(figsize=(16, 10), dpi=100) 
rplt.hist(h_response, label='response matrix') 
h_response.Draw() 
plt.xlabel('reconstructed $E_{\mathrm{T}}^{miss}$') 
plt.ylabel('Generated $E_{\mathrm{T}}^{miss}$') 
plt.title('Response Matrix') 
plt.savefig('ResponseMatrix.png') 

, 이것은 오류 MSG 나에게 잎 :

나는이에 사용하는 코드는

Traceback (most recent call last): 
    File "/storage/Dropbox/Workspace/Analysis/DailyPythonScripts/src/unfolding.py", line 66, in <module> 
    rplt.hist(h_response, label='response matrix') 
    File "/usr/local/lib/python2.7/dist-packages/rootpy-0.7.0_a0-py2.7-linux-x86_64.egg/rootpy/plotting/root2matplotlib.py", line 140, in hist 
    snap_zero=snap_zero) 
    File "/usr/local/lib/python2.7/dist-packages/rootpy-0.7.0_a0-py2.7-linux-x86_64.egg/rootpy/plotting/root2matplotlib.py", line 82, in _set_bounds 
    ywidth = ymax - ymin 
TypeError: unsupported operand type(s) for -: 'list' and 'list' 
분명히

내가 잘못 rootpy2matplotlib 모듈을 사용하고, 그래서보고했다 : 모듈은 hist, bar 및 errorbar 기능을 제공합니다. -> 2D에 해당하지 않습니다.

내가 누락 된 항목이 있습니까? 쉬운 해결 방법이 있습니까?

추신 : 나는이 질문에 'rootpy'태그로 태그를 지정하고 싶습니다. 그러나 불가능합니다. 이 질문은 매우 구체적이기 때문에 사과드립니다.

답변

3

rootpy의 root2matplotlib 인터페이스는 이제 2D ROOT 막대 그래프를 그리기위한 hist2d, imshow 및 contour 함수를 제공합니다. 여기에 예를 참조하십시오

https://github.com/rootpy/rootpy/blob/master/examples/plotting/plot_matplotlib_hist2d.py

from matplotlib import pyplot as plt 
from rootpy.plotting import root2matplotlib as rplt 
from rootpy.plotting import Hist2D 
import numpy as np 

a = Hist2D(100, -3, 3, 100, 0, 6) 
a.fill_array(np.random.multivariate_normal(
    mean=(0, 3), 
    cov=np.arange(4).reshape(2, 2), 
    size=(1E6,))) 

fig, (ax1, ax2, ax3) = plt.subplots(nrows=1, ncols=3, figsize=(15, 5)) 

ax1.set_title('hist2d') 
rplt.hist2d(a, axes=ax1) 

ax2.set_title('imshow') 
im = rplt.imshow(a, axes=ax2) 

ax3.set_title('contour') 
rplt.contour(a, axes=ax3) 

fig.subplots_adjust(right=0.8) 
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]) 
fig.colorbar(im, cax=cbar_ax) 

plt.show() 

enter image description here

+0

대단히 감사합니다! – DragonTux

3

TH2D 히스토그램이 포함 된 ROOT 파일에서 스크립트를 시험해 보았습니다. 모든 것이 효과가있었습니다. 내

/usr/local/lib/python2.7/dist-packages/rootpy-dev을 확인하는 경우 0.7.0

: 의 version.txt

/옵션/rootpy 번호 고양이는 저를 준다 -py2.7.egg/rootpy/plotting/root2matplotlib.py

오류 메시지와 비교하면 다른 버전의 rootpy를 사용하고있는 것처럼 보입니다.

rootpy의 최신 버전을 사용해보십시오.