python - 将列转换为 4 维数据以绘制 3d 曲面图
问题描述
我尝试重塑我的数据以绘制 3d 曲面图。我有 4 列,我想将它们用于 3 轴,将第 4 列用于表面颜色。但我正在努力让数据以正确的形式出现。
到目前为止,我已经完成了前 3 个维度的工作:
def plotly_4d(data):
df1 = pd.DataFrame.from_records(data, columns=['selcperc', 'mperiod', 'rocperiod', 'value'])
df = df1[~(df1['selcperc'].isin([2]))]
df= df.pivot_table(index=['mperiod'], columns=['rocperiod'], values='value').reset_index()
del df['mperiod']
df.drop(df.index[0])
print(df)
fig = go.Figure(data=[go.Surface(z=df.values)])
fig.update_traces(contours_z=dict(show=True, usecolormap=True,
highlightcolor="limegreen", project_z=True))
fig.update_layout(title_text="Analysis of Strategy", autosize=False, width=700, height=700,
margin=dict(l=65, r=50, b=65, t=90))
fig.show()
data = [[1, 100, 100, 39.75640778351649], [1, 100, 110, 9.872282288628153], [1, 100, 120, 9.872282288628153], [1, 100, 130, 9.642593626259359], [1, 110, 100, 8.080838244365983], [1, 110, 110, 8.080838244365983], [1, 110, 120, 8.080838244365983], [1, 110, 130, 7.800644723300946], [1, 120, 100, 16.665716278906633], [1, 120, 110, 16.665716278906633], [1, 120, 120, 16.665716278906633], [1, 120, 130, 16.24384694969096], [1, 130, 100, 5.48409659630341], [1, 130, 110, 5.48409659630341], [1, 130, 120, 5.48409659630341], [1, 130, 130, 5.48409659630341], [
2, 100, 100, 28.07034496404147], [2, 100, 110, 2.4858848187807294], [2, 100, 120, 2.4858848187807294], [2, 100, 130, 2.5146638062505695], [2, 110, 100, 2.2346947747962775], [2, 110, 110, 2.2346947747962775], [2, 110, 120, 2.2346947747962775], [2, 110, 130, 2.257673458249152], [2, 120, 100, 1.3453241481836469], [2, 120, 110, 1.3453241481836469], [2, 120, 120, 1.3453241481836469], [2, 120, 130, 1.3663313544445679], [2, 130, 100, 0.9013560706526865], [2, 130, 110, 0.9013560706526865], [2, 130, 120, 0.9013560706526865], [2, 130, 130, 0.9013560706526865]]
plotly_4d(data)
有谁知道如何在表面函数中转换数据并将其正确归因?提前致谢!
解决方案
推荐阅读
- angular - Angular-routing:html-template 中的路由链接无法与路由模块中定义的路由匹配
- r - ggplot中的非矩形图例
- git - 从推送的提交中删除文件而不从树 git 中删除它
- python - 气流:如何将变量 obtenida de mi DB 传递给 SimpleHttpOperator 函数
- oracle - TOAD:无法从包中调试程序
- firebase - 设备上的 ML Kit Face Detection 是否可供商业公司免费使用?
- vue.js - 预期对象,得到数组 laravel vue 分页
- kotlin - 如何获取 API 28 的光标
- javascript - 仅使用 JavaScript 上传图像的 HTML 表单
- c++ - ./libbar.so:未定义符号:__gxx_personality_v0,如何解决?