I have just started using Plotly and by looking in this Forum I have not seen a similar question asked so I hope I am not duplicating a question.
Basically, I have two vectorial fields, which I would like to plot, with different colors, on the same graphs. Is anybody able to point me towards some documentation that can help me with this question?
HI @PolTricerri welcome to th forums. It depends a bit on your data and how you want the final graph to look like but here you can find some inforamtion:
A basic example for overlaying two quiver plots:
import plotly.figure_factory as ff
import numpy as np
scaleratio=0.8
scale=0.4
# create data
x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
u = np.cos(x)*y
v = np.sin(x)*y
# base figure (including first trace)
fig = ff.create_quiver(x, y, u, v, scale=scale, scaleratio=scaleratio)
# create second figure object, extract trace --> .data[0]
trace2 = ff.create_quiver(x, y, v, u, scale=scale, scaleratio=scaleratio).data[0]
# add trace to figure
fig.add_traces(trace2)
# set heigth and width and show figure
fig.update_layout(height=500, width=500)
fig.show()
@PolTricerri You can control the plot aesthetics by setting for each quiver its own scale, arrow_scale, angle and line_width. A global settings for these parameters can lead to awful plots.
import plotly.graph_objects as go
import plotly.figure_factory as ff
from numpy import sin, cos, pi
import numpy as np
x, y = np.mgrid[0:2:16j,0:2:16j]
u = sin(x*pi) * cos(y*pi)
v = cos(x*pi) * sin(y*pi)
fig = ff.create_quiver(x, y, u, v,
scale=0.15,
arrow_scale=.4,
angle=pi/15,
name='quiver1',
line=dict(width=1.15, color='#8f180b'))
fig.update_layout(width=500, height=500)
x,y = np.meshgrid(np.arange(0, 2, .2),
np.arange(0, 2, .25))
z = x*np.exp(-x**2 - y**2)
v, u = np.gradient(z, .2, .2)
# Second quiver
fig.add_trace(ff.create_quiver(x, y, u, v,
scale=.25,
arrow_scale=.3,
angle=pi/15,
name='quiver2',
line_width=1.15).data[0])
# Add an equilibrium point of the second vector field to figure
fig.add_trace(go.Scatter(x=[.75], y=[0,0],
mode='markers',
marker_size=8, marker_color='red',
name='equilibrium'))