Iβm looking for a way to render a quiver plot interactive with the use of ipywidgets.
Say for example I have the following code
import numpy as np
import plotly.figure_factory as ff
import plotly.graph_objects as go
import ipywidgets as widgets
# Some vectors data
x=[0, 1, 2]
y=[0, 1, 0]
u=[-1, 2, 1]
v=[-0.2, 0.5, -1.7]
# the quiver plot
fig = ff.create_quiver(x, y, u, v,
scale=0.3,
arrow_scale=.30,
name='quiver',
line=dict(width=1))
# some extra data
xx=2*np.random.rand(5)
yy=0.2+1.5*np.random.rand(5)
trace=dict(type='scatter', x=xx, y=yy, mode='markers',
marker=dict(color='red', size=6)
)
# the interactive plot
fw = go.FigureWidget(data=[fig.data[0], trace], layout=fig.layout)
# amplitude slider (i.e. A*u and A*v)
A = widgets.FloatSlider(min=0, max=3, step=0.5, description="Amplitude",
continuous_update=True)
# the callback to update the graph when changing amplitude
def update(change):
pass
# ?????????????????????????
# Link the slider and the callback
A.observe(update, names='value')
# Display slider + figure
display(widgets.VBox([A, fw]))
How could I (efficiently) update the figure given the value of the amplitude (say to multiply the length of each vector for example)? (I know that I can change the length of the arrows with the attribute βscaleβ, but this is just a dummy example, the idea is to apply some more complicated transformation on my vectors eventually)
Thank you so much in advance for your help , and for this fantastic library. I really love all the possibilities it offers for scientific computing