简体   繁体   English

使用mplot3D绘制DataFrame

[英]Using mplot3D to plot DataFrame

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. 有更多的块,但是如您所见,每个cost_threshold包含10种S型斜率。 There are also 10 cost thresholds. 还有10个成本阈值。

I am trying to make a 3D plot of this per the surface plot here . 我正在尝试根据此处的表面图制作3D图。 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. X,Y和Z必须是2D数组。

How can I create the X, Y and ZI need to get this in the format they need? 如何创建需要的X,Y和ZI格式?

Z , the vertical axis, should be f1 , and cost_threshold and sigmoid_slope would be X and Y . 垂直轴Z应该为f1cost_thresholdsigmoid_slopeXY

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? 另外,我如何添加一个单独的表面图(模型no_model ,然后将此表面图覆盖到该表面图( f1列的值不同)呢?

UPDATE 更新

I know how to get the 2D array for Z , via the pivot table: 我知道如何通过数据透视表获取Z的2D数组:

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 . 仍然不知道如何为XZ创建一个。

This is how to get X, Y and Z respectively: 这是分别获得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

If you pass these into the plot, you get: 如果将它们传递到情节中,则会得到:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM