p不可调用列表

2024-10-01 09:21:10 发布

您现在位置:Python中文网/ 问答频道 /正文

这是给我错误的代码部分。我试着给这个情节一个从12到3的范围。它是一个对数函数,所以它是12比3,而不是3到12,以防有人问。在

pp = PdfPages('BV_V.pdf')
plt.plot(BVcolor, Vmag, 'go')
plt.xlabel('B-V color') 
plt.ylabel('Magnitude of V')
plt.errorbar(BVcolor, Vmag, xerr=BVerror, yerr=Verror, fmt='bo')
plt.xlim([0.5,1.5])
plt.ylim([12.0,3.0])
pp.savefig()
plt.close()
pp.close()

我得到的错误是

^{pr2}$

--->;83plt.xlim公司([0.5,1.5])

84 plt.ylim([12.0,-3.0])
85 pp.savefig()

TypeError:“list”对象不可调用

抱歉,这是新来的。以下是我正在执行的部分的完整代码:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
data = np.loadtxt("hyades.dat", skiprows = 1)
starnum = data[0:,0]
para = data[0:,1]
error1 = data[0:,2]
RAh = data[0:,3]
RAm = data[0:,4]
RAs = data[0:,5]
DECdg = data[0:,6] 
DECm = data[0:,7]
DECs = data[0:,8]
RA = (RAh * 15) + (RAm / 4) + (RAs / 240)
DEC = (DECdg) + (DECm / 60) + (DECs / 3600)
Vmag = data[0:,9]
Verror = data[0:,10]
BVcolor = data[0:,11]
BVerror = data[0:,12]

pp = PdfPages('V__Verr.pdf')
plt.plot(Vmag, Verror, 'ro')
plt.xlabel('Magnitude of V') 
plt.ylabel('Error of V magnitude')
pp.savefig()
plt.close()
pp.close()

pp = PdfPages('BV_V.pdf')
plt.plot(BVcolor, Vmag, 'go')
plt.xlabel('B-V color') 
plt.ylabel('Magnitude of V')
plt.errorbar(BVcolor, Vmag, xerr=BVerror, yerr=Verror, fmt='bo')
plt.xlim([0.5,1.5])
plt.ylim([12.0,-3.0])
pp.savefig()
plt.close()
pp.close()

distance = 1000 / para #in parsecs
paraerror = error1
errordist = paraerror / (1e-3*(para**2))
paramean = np.mean(distance)
parastd = np.std(distance)

pp = PdfPages('Histogram.pdf')
plt.hist(distance, bins = 50 )
plt.xlabel('Distance (pc)')
plt.ylabel('Star Number')
pp.savefig()
plt.close()
pp.close()

透明体数据在这里:http://speedy.sh/a4bhG/hyades.dat


Tags: ofclosedatapdfnppltppdistance
1条回答
网友
1楼 · 发布于 2024-10-01 09:21:10

NB:对于matplotlib的早期版本,此答案在编写时是有效的。这不再有效。见下文

请换一下:

plt.xlim([0.5,1.5])
plt.ylim([12.0,3.0])

^{pr2}$

对于Matplotlib的更现代版本,

我知道在Matplotlib的最新版本中,matplotlib.pyplot的API发生了变化。xlimylim不再是列表;相反,它们是函数,并取代了{},后者已被弃用,不再存在。在

如果使用更现代的Matplotlib,OP的代码可以正常工作。在

相关问题 更多 >