Skip to content

Instantly share code, notes, and snippets.

@Erlemar
Last active October 20, 2022 04:04
Show Gist options
  • Save Erlemar/66ebb7bb760930c3b3d38bb482b7b2b1 to your computer and use it in GitHub Desktop.
Save Erlemar/66ebb7bb760930c3b3d38bb482b7b2b1 to your computer and use it in GitHub Desktop.
import plotly.graph_objects as go
import numpy as np
import pandas as pd
df = pd.read_csv('/Users/andreylukyanenko/Downloads/df_numpy_3d_B4_pred.csv')
# Create figure
fig = go.Figure()
# Add traces, one for each slider step
for step in range(1, 126):
df_small = df.loc[df['j'] == step]
fig.add_trace(
go.Scatter3d(
visible=False,
line=dict(color="#00CED1", width=6),
name="𝜈 = " + str(step),
x=df_small.i.values,
y=df_small.j.values,
z=df_small['k'],
marker=dict(
size=3,
color=df_small.pred_P.values, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8,
colorbar=dict(thickness=20)
)))
for step in range(1, 126):
df_small = df.loc[df['i'] == step]
fig.add_trace(
go.Scatter3d(
visible=False,
line=dict(color="#00CED1", width=6),
name="𝜈 = " + str(step),
x=df_small.i.values,
y=df_small.j.values,
z=df_small['k'],
marker=dict(
size=3,
color=df_small.pred_P.values, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8,
colorbar=dict(thickness=20)
)))
for step in range(1, 126):
df_small = df.loc[df['k'] == min(step, df['k'].max())]
fig.add_trace(
go.Scatter3d(
visible=False,
line=dict(color="#00CED1", width=6),
name="𝜈 = " + str(step),
x=df_small.i.values,
y=df_small.j.values,
z=df_small['k'],
marker=dict(
size=3,
color=df_small.pred_P.values, # set color to an array/list of desired values
colorscale='Viridis', # choose a colorscale
opacity=0.8,
colorbar=dict(thickness=20)
)))
# Make 10th trace visible
fig.data[0].visible = True
# Create and add slider
steps = []
for i in range(125):
step = dict(
method="update",
args=[{"visible": [False] * len(fig.data)},
{"title": "Slider switched to step: " + str(i)}], # layout attribute
)
step["args"][0]["visible"][i] = True # Toggle i'th trace to "visible"
step["args"][0]["visible"][i + 125] = True # Toggle i'th trace to "visible"
step["args"][0]["visible"][i + 250] = True # Toggle i'th trace to "visible"
steps.append(step)
sliders = [dict(
active=10,
currentvalue={"prefix": "Frequency: "},
pad={"t": 50},
steps=steps
)]
fig.update_layout(
sliders=sliders
)
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment