Python : 2d contour plot with fixed x and y for 6 series of fractional data (z)
<p>I'm trying to use a contour plot to show an array of fractional data (between 0 and 1) at 6 heights (5, 10, 15, 20, 25, and 30) with a fixed x-axis (the "WN" series, 1 to 2300). y (height) is different for each series and discontinuous so I need to interpolate between heights. </p>

<pre><code>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
...
</code></pre>

<p>Any ideas? Thank you!</p>

<p>Using matplotlib, you need your X (row), Y (column), and Z values. The matplotlib function expects data in a certain format. Below, you'll see the meshgrid helps us get that format.</p>

<p>Here, I use pandas to import your data that I saved to a csv file. You can load your data any way you'd like though. The key is prepping your data for the plotting function.</p>

<pre><code>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)
</code></pre>

<p><a href="https://i.stack.imgur.com/T2uTZ.png" rel="nofollow"><img src="https://i.stack.imgur.com/T2uTZ.png" alt="enter image description here"></a></p>

python python-2.7 pandas matplotlib