我有一个如下所示的 csv 文件:
Axis [m],Channel 1 [],Channel 2 [],Channel 3 [],Channel 4 []
0,11.87772978,65.2269997,7.103221875,6.324708559
1.34E-08,17.65605321,75.09093444,8.309697828,14.87524308
2.69E-08,15.19155521,77.12878487,12.31291774,9.457125362
4.03E-08,23.85118853,88.76138941,20.10571063,8.041540228
5.38E-08,18.77440037,87.15681445,14.53884458,13.36609689
6.72E-08,19.54841939,117.9766076,16.87197928,18.50902666
8.06E-08,33.37595782,102.2086995,40.59474863,9.451430137
我想使用 matplotlib 绘制前两列中的值
我有以下代码:
import matplotlib.pyplot as plt
import pylab, csv
x=[]
y=[]
with open("test.csv","rU") as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
if re.search("\d",row[0]):
x.append(float(row[0]))
y.append(float(row[1]))
fig = plt.figure()
ax1 = fig.add_subplot(121)
ax1.scatter(x,y,color='blue',s=5,edgecolor='none')
ax1.set_aspect(1./ax1.get_data_ratio()) # make axes square
pylab.savefig('test.jpg')
但是,这会将我所有的 x 值(总计 122 个值)绘制为围绕 0 的一条线(而不是我期望的曲线),请参见此处的示例。我认为这是因为 x 轴的比例将所有数据聚集在 0 左右。我想我需要改变 x 轴的比例来处理小数字?
任何帮助,一如既往,将不胜感激!