[英]Using mplot3D to plot DataFrame
我有一个这样的数据框:
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
有更多的块,但是如您所见,每个cost_threshold包含10种S型斜率。 还有10个成本阈值。
我正在尝试根据此处的表面图制作3D图。 谁的演示是:
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和Z必须是2D数组。
如何创建需要的X,Y和ZI格式?
垂直轴Z
应该为f1
, cost_threshold
和sigmoid_slope
为X
和Y
另外,我如何添加一个单独的表面图(模型no_model
,然后将此表面图覆盖到该表面图( f1
列的值不同)呢?
更新
我知道如何通过数据透视表获取Z
的2D数组:
Z = df.pivot_table('f1', 'cost_threshold', 'sigmoid_slope', fill_value=0).as_matrix()
仍然不知道如何为X
和Z
创建一个。
这是分别获得X,Y和Z的方法:
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
如果将它们传递到情节中,则会得到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.