python中带有Z轴数据的2D图

问题描述

我想从该数据(文件)中绘制图形:

# file name: c7.csv
... 
...
...
Scan Start
2d statistical,-32,-24,-16,-8,8,16,24,32
120,0.254592,0.195414,0.00428721,0.0114557,0.0147995,0.0458237,0.0924488,0.161643,0.286074
112,0.251826,0.141975,3.81476e-07,1.33516e-06,2.67033e-06,0.000362783,0.0192802,0.126411,0.255406
104,0.251825,0.127342,8.16358e-05,0.121867,0.251922
96,0.125952,0.0998646,0.251903
88,0.123279,0.0703892,0.251903
80,0.0669492,0.0437135,0.251903
72,0.0133867,0.0134152,0.251845
64,0.251847,0.00226196,0.000735103,0.249137
56,0.254034,5.14992e-06,5.72213e-07,0.235424
48,0.265368,0.219798
40,0.282969,0.198044
32,0.333191,0.172414
24,0.363716,0.165892
16,0.343822,0.168372
8,0.307494,0.186618
0,0.297795,0.196873
-8,0.283094,0.191286
-16,0.305736,0.174678
-24,0.360888,0.173295
-32,0.347627,0.179868
-40,0.306325,0.189885
-48,0.287914,0.2148
-56,0.259855,1.02998e-05,0.229949
-64,0.252141,0.00180457,0.000303082,0.247241
-72,0.0219065,0.0110576,0.251671
-80,0.0676513,0.0373565,0.251922
-88,0.121092,0.0683341,0.251903
-96,0.125971,0.0962393,0.251903
-104,0.126107,0.000229076,0.114732,0.251941
-112,0.251831,0.131269,2.28885e-06,4.63493e-05,0.000350958,0.0314566,0.13105,0.260355
-120,0.269835,0.181753,0.00982261,0.0178109,0.0331482,0.0722836,0.110299,0.175774,0.299987
Scan End
...
...
...

结果应该看起来是

首先,我从.csv文件(c7.csv)读取数据

with open('c7.csv',newline='') as f:
  reader = csv.reader(f)
  data = list(reader)

2nd,我从输入数据中找到开始 end 位置

cnt_start = 0;
while(data[cnt_start][0] != 'Scan Start'):
  cnt_start+=1

cnt_end = 0;
while(data[cnt_end][0] != 'Scan End'):
  cnt_end+=1

第三,我从输入数据的 begin end 位置

抓取了从“扫描开始”到“扫描结束”的数据
vals = []
for i in range(cnt_start +1,cnt_end):
  vals.append(data[i])

删除str'2d statistics'

vals[0].pop(0) 

4,由于数据是 string 类型,我将其转换为float类型

for i in vals:
  for j in i:
    j = float(j)

5,我从以前的数据中提取行标度和列标度

column_vals = []
column_vals = vals.pop(0)

row_vals = []
for i in vals:
  row_vals.append(i.pop(0))

最后,我显示了绘图所需数据的数据输出

print(column_vals) # x scale
print(row_vals) # y scale
print(vals) # z data

All of code above in here (如果已安装所需的软件包,则可以执行此代码

所需数据似乎已经准备好。

下一步如何做(绘制2D并添加比例尺x_data,y_data)?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)