I have a dataframe like this:
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
There are more blocks but as you can see, each cost_threshold contains 10 types of sigmoid slopes. There are also 10 cost thresholds.
I am trying to make a 3D plot of this per the surface plot here . Whose demo is:
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()
X, Y and Z have to be 2D arrays.
How can I create the X, Y and ZI need to get this in the format they need?
Z
, the vertical axis, should be f1
, and cost_threshold
and sigmoid_slope
would be X
and Y
.
In addition, how would I add a separate surface plot, where the model is say no_model
, and then overlay this surface plot to this, where the values of the f1
column are different?
UPDATE
I know how to get the 2D array for Z
, via the pivot table:
Z = df.pivot_table('f1', 'cost_threshold', 'sigmoid_slope', fill_value=0).as_matrix()
Still don't know how to create one for X
and Z
.
This is how to get X, Y and Z respectively:
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
If you pass these into the plot, you get:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.