简体   繁体   English

二维轮廓 plot 使用 Python 中的数据文件

[英]2D contour plot using a data file in Python

I have a data file which comprises of 5 rows and 4642 columns.我有一个包含 5 行和 4642 列的数据文件。 I wanted to create a contour file using 2,3 and 5 row.我想使用 2,3 和 5 行创建一个轮廓文件。 I tried to write a simple code of Python which looks like:我尝试编写一个简单的 Python 代码,如下所示:

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
import math 

df = pd.read_csv('inlet_v.csv', skiprows=1, header = None)
tt = plt.contourf(df.iloc[:,1], df.iloc[:,2], df.iloc[:,4])

plt.show()

But as expected that since the "z" or 3rd entry in the data is not 2D thus it is throwing and error which says:但正如预期的那样,由于数据中的“z”或第三个条目不是 2D 的,因此它会抛出错误并显示:

 tt = plt.contourf(df.iloc[:,1], df.iloc[:,2], df.iloc[:,4])
TypeError: Input z must be a 2D array.

Any comment/suggestion will be a great help.任何评论/建议都会有很大帮助。 The data looks like:数据如下:

0   0.02    0   0.12674 5.4805E-05
0   0.021   0   0.12674 5.7583E-05
0   0.02    0.03    0.12674 2.1107E-05
0   0.021   0.03    0.12674 2.2177E-05
0   0.02098 0   0.12674 0.00011227
0   0.02096 0   0.12674 0.00022133
0   0.02094 0   0.12674 0.00032951
0   0.02092 0   0.12674 0.00043639
0   0.0209  0   0.12674 0.00054155
0   0.02088 0   0.12674 0.00064457
0   0.02086 0   0.12674 0.00074506
0   0.02084 0   0.12674 0.00084261
0   0.02082 0   0.12674 0.00093683
0   0.0208  0   0.12674 0.0010274
0   0.02078 0   0.12674 0.0011138
0   0.02076 0   0.12674 0.0011959
0   0.02074 0   0.12674 0.0012733
0   0.02072 0   0.12674 0.0013457
0   0.0207  0   0.12674 0.0014127
0   0.02068 0   0.12674 0.0014742
0   0.02066 0   0.12674 0.0015299
0   0.02064 0   0.12674 0.0015795
0   0.02062 0   0.12674 0.0016229
0   0.0206  0   0.12674 0.0016599
0   0.02058 0   0.12674 0.0016904
0   0.02056 0   0.12674 0.0017142
0   0.02054 0   0.12674 0.0017312
0   0.02052 0   0.12674 0.0017414
0   0.0205  0   0.12674 0.0017448
0   0.02048 0   0.12674 0.0017413
0   0.02046 0   0.12674 0.0017309
0   0.02044 0   0.12674 0.0017137
0   0.02042 0   0.12674 0.0016897
0   0.0204  0   0.12674 0.0016591
0   0.02038 0   0.12674 0.0016219
0   0.02036 0   0.12674 0.0015783
0   0.02034 0   0.12674 0.0015285
0   0.02032 0   0.12674 0.0014727
0   0.0203  0   0.12674 0.0014111
0   0.02028 0   0.12674 0.0013439
0   0.02026 0   0.12674 0.0012714
0   0.02024 0   0.12674 0.0011939
0   0.02022 0   0.12674 0.0011117
0   0.0202  0   0.12674 0.0010251
0   0.02018 0   0.12674 0.00093448
0   0.02016 0   0.12674 0.00084017
0   0.02014 0   0.12674 0.00074254
0   0.02012 0   0.12674 0.00064199
0   0.0201  0   0.12674 0.00053891
0   0.02008 0   0.12674 0.0004337
0   0.02006 0   0.12674 0.00032678
0   0.02004 0   0.12674 0.00021857
0   0.02002 0   0.12674 0.0001095
0   0.02002 0.03    0.12674 4.2172E-05
0   0.02004 0.03    0.12674 8.4178E-05
0   0.02006 0.03    0.12674 0.00012585
0   0.02008 0.03    0.12674 0.00016703
0   0.0201  0.03    0.12674 0.00020755
0   0.02012 0.03    0.12674 0.00024725
0   0.02014 0.03    0.12674 0.00028598
0   0.02016 0.03    0.12674 0.00032358
0   0.02018 0.03    0.12674 0.0003599
0   0.0202  0.03    0.12674 0.0003948
0   0.02022 0.03    0.12674 0.00042815
0   0.02024 0.03    0.12674 0.00045981
0   0.02026 0.03    0.12674 0.00048966
0   0.02028 0.03    0.12674 0.00051757
0   0.0203  0.03    0.12674 0.00054345
0   0.02032 0.03    0.12674 0.00056718
0   0.02034 0.03    0.12674 0.00058868
0   0.02036 0.03    0.12674 0.00060786
0   0.02038 0.03    0.12674 0.00062463
0   0.0204  0.03    0.12674 0.00063895
0   0.02042 0.03    0.12674 0.00065075
0   0.02044 0.03    0.12674 0.00065998
0   0.02046 0.03    0.12674 0.00066661
0   0.02048 0.03    0.12674 0.00067061
0   0.0205  0.03    0.12674 0.00067197
0   0.02052 0.03    0.12674 0.00067068
0   0.02054 0.03    0.12674 0.00066675
0   0.02056 0.03    0.12674 0.00066018
0   0.02058 0.03    0.12674 0.00065102
0   0.0206  0.03    0.12674 0.00063928
0   0.02062 0.03    0.12674 0.00062503
0   0.02064 0.03    0.12674 0.00060831
0   0.02066 0.03    0.12674 0.00058919
0   0.02068 0.03    0.12674 0.00056776
0   0.0207  0.03    0.12674 0.00054408
0   0.02072 0.03    0.12674 0.00051825
0   0.02074 0.03    0.12674 0.00049039
0   0.02076 0.03    0.12674 0.00046059
0   0.02078 0.03    0.12674 0.00042897
0   0.0208  0.03    0.12674 0.00039567
0   0.02082 0.03    0.12674 0.0003608
0   0.02084 0.03    0.12674 0.00032451
0   0.02086 0.03    0.12674 0.00028694
0   0.02088 0.03    0.12674 0.00024825
0   0.0209  0.03    0.12674 0.00020857
0   0.02092 0.03    0.12674 0.00016807
0   0.02094 0.03    0.12674 0.0001269
0   0.02096 0.03    0.12674 8.524E-05
0   0.02098 0.03    0.12674 4.324E-05
0   0.02    0.00033333  0.12674 6.2219E-05
0   0.02    0.00066667  0.12674 6.1847E-05
0   0.02    0.001   0.12674 3.3238E-05
0   0.02    0.0013333   0.12674 -1.1494E-05
0   0.02    0.0016667   0.12674 -5.0586E-05
0   0.02    0.002   0.12674 -6.5667E-05
0   0.02    0.0023333   0.12674 -5.2608E-05
0   0.02    0.0026667   0.12674 -2.3248E-05
0   0.02    0.003   0.12674 2.9907E-06
0   0.02    0.0033333   0.12674 1.1943E-05
0   0.02    0.0036667   0.12674 3.5166E-06
0   0.02    0.004   0.12674 -9.2539E-06
0   0.02    0.0043333   0.12674 -1.0113E-05
0   0.02    0.0046667   0.12674 8.3196E-06
0   0.02    0.005   0.12674 3.8492E-05
0   0.02    0.0053333   0.12674 6.2114E-05
0   0.02    0.0056667   0.12674 6.1961E-05
0   0.02    0.006   0.12674 3.3541E-05
0   0.02    0.0063333   0.12674 -1.1146E-05
0   0.02    0.0066667   0.12674 -5.0363E-05
0   0.02    0.007   0.12674 -6.5664E-05
0   0.02    0.0073333   0.12674 -5.2792E-05
0   0.02    0.0076667   0.12674 -2.3484E-05
0   0.02    0.008   0.12674 2.8461E-06
0   0.02    0.0083333   0.12674 1.195E-05
0   0.02    0.0086667   0.12674 3.6189E-06
0   0.02    0.009   0.12674 -9.184E-06
0   0.02    0.0093333   0.12674 -1.0179E-05
0   0.02    0.0096667   0.12674 8.1163E-06
0   0.02    0.01    0.12674 3.8261E-05
0   0.02    0.010333    0.12674 6.2008E-05
0   0.02    0.010667    0.12674 6.2074E-05
0   0.02    0.011   0.12674 3.3842E-05
0   0.02    0.011333    0.12674 -1.0798E-05
0   0.02    0.011667    0.12674 -5.0139E-05
0   0.02    0.012   0.12674 -6.566E-05
0   0.02    0.012333    0.12674 -5.2975E-05
0   0.02    0.012667    0.12674 -2.372E-05
0   0.02    0.013   0.12674 2.7004E-06
0   0.02    0.013333    0.12674 1.1957E-05
0   0.02    0.013667    0.12674 3.721E-06
0   0.02    0.014   0.12674 -9.1134E-06
0   0.02    0.014333    0.12674 -1.0244E-05
0   0.02    0.014667    0.12674 7.9138E-06
0   0.02    0.015   0.12674 3.803E-05
0   0.02    0.015333    0.12674 6.1901E-05
0   0.02    0.015667    0.12674 6.2186E-05

Using @JohanC ( https://stackoverflow.com/users/12046409/johanc ) comment I could now plot it correctly, the code looks like:使用@JohanC ( https://stackoverflow.com/users/12046409/johanc ) 评论我现在可以正确使用 plot 它,代码如下所示:

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import math 

df = pd.read_csv('inlet_v.csv', skiprows=1, header = None)

plt.figure(1)
tt = plt.tricontourf(df.iloc[:,2], df.iloc[:,1], df.iloc[:,4], cmap="jet")
plt.show()

The corresponding plot looks like the attached figure.对应的plot如附图。 Thanks again @JohanC for your kind help.再次感谢@JohanC 的帮助。 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM