I have managed to make a plotly graph based on this code sample from Plotly documentation:
import plotly.graph_objects as go
import numpy as np
# Create figure
fig = go.Figure()
# Add traces, one for each slider step
for step in np.arange(0, 5, 0.1):
fig.add_trace(
go.Scatter(
visible=False,
line=dict(color="#00CED1", width=6),
name=" = " + str(step),
x=np.arange(0, 10, 0.01),
y=np.sin(step * np.arange(0, 10, 0.01))))
# Make 10th trace visible
fig.data[10].visible = True
# Create and add slider
steps = []
for i in range(len(fig.data)):
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"
steps.append(step)
sliders = [dict(
active=10,
currentvalue={"prefix": "Frequency: "},
pad={"t": 50},
steps=steps
)]
fig.update_layout(
sliders=sliders
)
fig.show()
Problem is that, as I am instead visualizing relatively big go.Image
s, the preparation of the plots is extremely slow and not suitable for the final interactive Streamlit app that I am trying to create.
To make it faster, I thought to have non-interactive plots which (I guess so at least) should be much faster. There is, however, no interactive=False
option for the plotly traces, or at least I cannot find them. There is option to export figure to a static image, but that would make no sense, as the figure would have to be prepared anyway before it would be exported to png and visualized as a static image.
So, is there any way to modify this Plotly example in a way that keeps the sliders but directly creates non-interactive plot from a Numpy array?
Or do I have to switch do a different library completely? Thanks.