hulyce
hulyce

Reputation: 470

Plotly: How to add quivers to an existing plot?

I'd like to add quivers to an existing figure with plotly (python). But the only peace of documentation I could find either create only one quiver (here) or a brand new figure (there).

Here's the example on plotly doc :

import plotly.figure_factory as ff

import numpy as np

x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
u = np.cos(x)*y
v = np.sin(x)*y

fig = ff.create_quiver(x, y, u, v)
fig.show()

If anyone has a better understanding of plotly that I do, I'd appreciate a lot a few explanations!

Thanks a lot,

Upvotes: 6

Views: 2704

Answers (1)

vestland
vestland

Reputation: 61184

Assuming that you'd like to add quivers to an existing ff.create_quiver() figure, all you have to do is:

  1. Create fig1 = ff.create_quiver(x, y, u, v),
  2. create another figure with other attributes fig2 = ff.create_quiver(x, y, u*0.9, v*2),
  3. and add the resulting fig2.data to fig1 using fig1.add_traces(data = fig2.data)

Plot:

enter image description here

Complete code:

import plotly.figure_factory as ff
import numpy as np

x,y = np.meshgrid(np.arange(0, 2, .2), np.arange(0, 2, .2))
u = np.cos(x)*y
v = np.sin(x)*y

fig1 = ff.create_quiver(x, y, u, v)

fig2 = ff.create_quiver(x, y, u*0.9, v*2)
fig1.add_traces(data = fig2.data)
fig1.show()

Upvotes: 4

Related Questions