-1

为什么这没有附加到ciand mag?我的数据显然有这个范围内的点。

import numpy as np
import csv
import matplotlib.pyplot as plt
import random
from pylab import *
ci = []
mag =[]
cntr = 0
#fig = plt.scatter()
#ax1 = fig.add_subplot(111)
#ax2 = twiny()
import csv
with open('test2.csv', 'r') as f:
    reader = csv.reader(f)
    for row in reader:
        try:
            if (float(row[0]) < 2.5) and (float(row[1]<15.0)) and (float(row[1]>-10.0)):
                ci.append(float(row[0]))
                mag.append(float(row[1]))
                cntr+=1
        except Exception, e:
            pass
print ci[1], mag[1]    

N = 50
x = ci
y = mag
area = .001
plt.scatter(x, y, s=area, alpha=0.25)
#plt.plot(x, y, ', ')
plt.xlabel('Color Index')
plt.ylabel('Magnitude')
plt.title('H-R Diagram')
plt.gca().invert_yaxis()
plt.show()
4

1 回答 1

3
float(row[1]<15.0)

float(row[1]>-10.0)

括号好像放错地方了。


如果row有所有浮点值,你可以这样做:

for row in reader:
    row = map(float, row)
    try:
        if (row[0] < 2.5) and (-10 < row[1] < 15.0):

或者,由于您只需要 中的前 2 个值row,您可以使用

row = map(float, row[:2])
于 2013-11-08T02:25:53.817 回答