我正在使用salem_executions_data.csv,这是这样的:
year,month,accusations,executions
1962,1,0,0
1962,2,3,0
1962,3,4,0
1962,4,22,0
1962,5,39,0
1962,6,3,1
1962,7,12,5
1962,8,23,5
1962,9,33,9
1962,10,1,0
1962,11,3,0
1962,12,0,0
1963,1,0,0
1963,2,0,0
1963,3,0,0
使用Python 2.7,我想要做的是:
到目前为止,我是这样的:
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('data/salem_executions_data.csv','r') as csvfile:
plots = csv.reader(csvfile, delimiter=',')
from itertools import islice
for row in islice(plots,1,None):
for row in plots:
temp=row[int(str(2))]
x.append(temp)
temp=row[int(str(3))]
y.append(temp)
plt.plot(x,y)
plt.xlabel('Accusations')
plt.ylabel('Executions')
plt.title('Accusations vs Executions')
plt.legend()
plt.show()
一旦执行了这些单元格,我就不会得到输出代码...有什么帮助吗?
在内联添加%matplotlib之后,这就是我得到的输出,您认为还好吗? enter image description here
更新v3:
将plt.plot更改为plt.scatter之后: