2016-10-14 93 views
0

我试图使用等高线图来显示在6高度(5,5)的分数数据(0和1之间) 10,15,20,25和30)与一个固定的x轴(“WN”系列,1至2300)。 y(高度)对于每个系列都是不同的,并且是不连续的,所以我需要在高度之间进行插值。Python:2d轮廓图与固定的x和y为6个系列的小数数据(z)

WN,5,10,15,20,25,30 
1,0.9984898,0.99698234,0.99547797,0.99397725,0.99247956,0.99098486 
2,0.99814528,0.99629492,0.9944489,0.99260795,0.99077147,0.98893934 
3,0.99765164,0.99530965,0.99297464,0.99064702,0.98832631,0.98601222 
4,0.99705136,0.99411237,0.99118394,0.98826683,0.98535997,0.9824633 
5,0.99606526,0.99214685,0.98824716,0.98436642,0.98050326,0.97665751 
6,0.98111153,0.96281821,0.94508928,0.92790776,0.91125059,0.89509743 
7,0.99266499,0.98539108,0.97816986,0.97100824,0.96390355,0.95685524 
... 

任何想法?谢谢!

回答

0

使用matplotlib,你需要你的X(行),Y(列)和Z值。 matplotlib函数需要某种格式的数据。下面,你会看到meshgrid帮助我们获得这种格式。

在这里,我使用熊猫导入您保存到csv文件的数据。您可以按照自己喜欢的方式加载数据。关键是准备你的数据绘图功能。

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

#import the data from a csv file 
data = pd.read_csv('C:/book1.csv') 

#here, I let the x values be the column headers (could switch if you'd like) 
#[1:] don't want the 'WN' as a value 
X = data.columns.values[1:] 

#Here I get the index values (a pandas dataframe thing) as the Y values 
Y = data['WN'] 

#don't want this column in your data though 
del data['WN'] 

#need to shape your data in preparation for plotting 
X, Y = np.meshgrid(X, Y) 

#see http://matplotlib.org/examples/pylab_examples/contour_demo.html 
plt.contourf(X,Y,data) 

enter image description here

相关问题