Using mplot3D to plot DataFrame
<p>I have a dataframe like this:</p>

<pre><code>     f1        model  cost_threshold  sigmoid_slope
366  0.140625  open          0.0001         0.0001
445  0.356055  open          0.0001         0.0010
265  0.204674  open          0.0001         0.0100
562  0.230088  open          0.0001         0.0500
737  0.210923  open          0.0001         0.1500
117  0.161580  open          0.0001         0.1000
763  0.231648  open          0.0001         0.3000
466  0.186228  open          0.0001         0.5000
580  0.255686  open          0.0001         0.7500
520  0.163478  open          0.0001         1.0000
407  0.152488  open          0.0010         0.0001
717  0.183946  open          0.0010         0.0010
708  0.201499  open          0.0010         0.0100
570  0.179720  open          0.0010         0.0500
722  0.200326  open          0.0010         0.1500
316  0.187692  open          0.0010         0.1000
240  0.243612  open          0.0010         0.3000
592  0.274322  open          0.0010         0.5000
254  0.309560  open          0.0010         0.7500
400  0.225460  open          0.0010         1.0000
148  0.494311  open          0.0100         0.0001
100  0.498199  open          0.0100         0.0010
155  0.473008  open          0.0100         0.0100
494  0.484625  open          0.0100         0.0500
754  0.504391  open          0.0100         0.1500
636  0.425798  open          0.0100         0.1000
109  0.446701  open          0.0100         0.3000
759  0.509829  open          0.0100         0.5000
345  0.522837  open          0.0100         0.7500
702  0.511971  open          0.0100         1.0000
</code></pre>

<p>There are more blocks but as you can see, each cost_threshold contains 10 types of sigmoid slopes. There are also 10 cost thresholds.</p>

<p>I am trying to make a 3D plot of this per the surface plot <a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots" rel="nofollow">here</a>. Whose demo is:</p>

<pre><code>from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)

plt.show()
</code></pre>

<p>X, Y and Z have to be 2D arrays.</p>

<p>How can I create the X, Y and Z I need to get this in the format they need? </p>

<p><code>Z</code>, the vertical axis, should be <code>f1</code>, and <code>cost_threshold</code> and  <code>sigmoid_slope</code> would be <code>X</code> and <code>Y</code>.</p>

<p>In addition, how would I add a separate surface plot, where the model is say <code>no_model</code>, and then overlay this surface plot to this, where the values of the <code>f1</code> column are different?</p>

<p><strong>UPDATE</strong></p>

<p>I know how to get the 2D array for <code>Z</code>, via the pivot table:</p>

<pre><code>Z = df.pivot_table('f1', 'cost_threshold', 'sigmoid_slope', fill_value=0).as_matrix()
</code></pre>

<p>Still don't know how to create one for <code>X</code> and <code>Z</code>.</p>

<p>This is how to get X, Y and Z respectively:</p>

<pre><code>Z = df.pivot_table('f1', 'cost_threshold', 'sigmoid_slope', fill_value=0).as_matrix()

Y = df.groupby("cost_threshold").sigmoid_slope.apply(pd.Series.reset_index, drop=True).unstack().values

Z = df.groupby("sigmoid_slope").cost_threshold.apply(pd.Series.reset_index, drop=True).unstack().values
</code></pre>

<p>If you pass these into the plot, you get:</p>

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

python pandas matplotlib dataframe mplot3d