Hi @Vale1,
To run the code below download the images i1.png-i5.png
from https://github.com/empet/Datasets/tree/master/Gnomonic-Projs. There are 15 frames in which i1-i5 are repeating 3 times.
(see {k%5+1}
in the for loop).
import plotly.graph_objects as go
import numpy as np
import base64
fig=go.Figure(go.Scatter(x=np.linspace(0,3, 50), y=np.random.rand(50), mode="lines",
line_color="white", line_width=2))
fig.update_layout(width=700, height=450)
#used images i1-i5.png three times; https://github.com/empet/Datasets/tree/master/Gnomonic-Projs
#set a local image as a background
img1 = base64.b64encode(open("images/i1.png", 'rb').read())
fig.update_layout(
images= [dict(
source='data:image/png;base64,{}'.format(img1.decode()),
xref="paper", yref="paper",
x=0, y=1,
sizex=1, sizey=1,
xanchor="left",
yanchor="top",
sizing="stretch",
layer="below")])
frames=[]
for k in range(1,15):
img = base64.b64encode(open(f"images/i{k%5 +1}.png", 'rb').read())
frames.append(go.Frame(layout=dict(images=[dict(source='data:image/png;base64,{}'.format(img.decode()))])))
fig.update(frames=frames)
fig.update_layout(updatemenus = [dict(
buttons = [
dict(
args = [None, {"frame": {"duration": 100, "redraw": True},
"fromcurrent": True}],
label = "Play",
method = "animate"
),
dict(
args = [[None], {"frame": {"duration": 0, "redraw": False},
"mode": "immediate",
"transition": {"duration": 0}}],
label = "Pause",
method = "animate"
)
],
direction = "left",
pad = {"r": 10, "t": 87},
showactive = False,
type = "buttons",
x = 0.1,
xanchor = "right",
y = 0,
yanchor = "top"
)] )
If you want to remove the grid lines just add to fig.update_layout, defined above, more two settings:
fig.update_layout(xaxis_showgrid=False, yaxis_showgrid=False)