list not callable for plot

2019-09-07 02:03发布

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

The error I am getting is

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

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

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

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 data is here: http://speedy.sh/a4bhG/hyades.dat

1条回答
2楼-- · 2019-09-07 02:31

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

to

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

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.

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

查看更多
登录 后发表回答