列表不可调用 [英] list not callable for plot

查看:60
本文介绍了列表不可调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码中给我错误的部分.我正在尝试将图表的范围设置为12到3.这是对数函数,因此它是12到3,而不是3到12,以防有人问.

This is the part of the code that gives me the error. I am trying to give the plot a range from 12 to 3. It is a logarithmic function so it is 12 to 3 not 3 to 12 in case anyone asks.

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

我得到的错误是

81 plt.ylabel('Magnitude of V')
 82 plt.errorbar(BVcolor, Vmag, xerr=BVerror, yerr=Verror, fmt='bo')

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

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

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

TypeError:'list'对象不可调用

TypeError: 'list' object is not callable

抱歉,刚接触这个.这是我正在做的部分的完整代码:

Sorry new to this. This is the complete code for the part I am doing:

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

Hyades数据在这里: http://speedy.sh/a4bhG/hyades.dat

Hyades data is here: http://speedy.sh/a4bhG/hyades.dat

推荐答案

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

请更改:

NB: This answer was valid when it was written, for an earlier version of matplotlib. This is not valid any longer. See below.

Please, change:

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

plt.set_xlim(0.5,1.5)
plt.set_ylim(12.0,3.0)

有关Matplotlib的更现代版本 ...

我知道对于Matplotlib的最新版本, matplotlib.pyplot 的API进行了更改. xlim ylim 不再是列表;取而代之的是,它们是函数,并且已替换了已弃用且不再存在的 set _ * .

For more modern versions of Matplotlib...

I know that for more recent versions of Matplotlib, matplotlib.pyplot's API changed. xlim and ylim are lists no longer; instead they're functions and have replaced set_*, which were deprecated and are there no longer.

使用更现代的Matplotlib,OP的代码可以正常工作.

OP's code would have worked without problems with a more modern Matplotlib.

这篇关于列表不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆