I try to reshape my data to get a 3d surface plot in plotly.
I have 4 columns and I would like to use them for the 3 axis and the 4th column for the surface color. But I am struggling to get the data in the right shape.
So far I made the first 3 dimensions work:
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)
Does anyone know how to transform the data and attribute it correctly in the surface function?
Thanks in advance!