2016-10-14 69 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

相關問題