How to pivot the arrows on a quiver plot

Whis this dataframe using matplotlib.quiver I create the next graph:

plt.quiver(df['x'], df['y'], df['u'], df['v'], units='xy',width=0.5,scale=1/0.025,pivot='mid',headlength=0)
plt.show()

resulting:

if I zoom in, the parameter pivot='mid' makes possible this::

I tried to create a similar plot with Plotly

fig=create_quiver(df['x'], df['y'], df['u'], df['v'], arrow_scale=0.001, scale=0.01)
fig.show()

but got this:

Is there any way to make the arrows rotate around the point (x,y) like in matplotlib (something like pivot='mid' )?

@esia2019
ff.create_quiver() has no keyword for mirroring the vectors through a point. But theoretically you can get the same plot as with matplotlib, with the following code:

import pandas as pd
import plotly.figure_factory as ff
from numpy import pi

df = pd.read_csv("quiver.csv")
fig=ff.create_quiver(2*df['x'].tolist(), 2*df['y'].tolist(), 
                  df['u'].tolist()+(df["u"].apply(lambda x: -1*x)).tolist(),
                  df['v'].tolist()+(df["v"].apply(lambda x: -1*x)).tolist(), 
                  arrow_scale=0.001, scale=0.01, angle=pi/18)

I said theoretically, because doubling the length of the dataframe we get a plot with lists x, y, u, v of length

2*len(df)=2*15360=30720

each. I did not succeed to get the fig, because the jupyter kernel stopped, most likely due to the large amount of data.

1 Like

Thanks mate. The large amount of data causes the jupyter kernel to stall, so I try it in Colab, it takes 18 minutes to complete the task, the result is exactly the same as matplotlib!

1 Like

@esia2019
I cannot understand why to plotly.py it takes so much to generate this plot.
Out of curiosity I also tested how long it takes, using the Julia version of plotly.py (PlotlyJS.jl).
I couldn’t believe it when I saw that in less than a second the quiver plot was displayed.
Time to get the fig is 8.131 ms:
https://nbviewer.org/gist/empet/3bb979f33cdc59b8267d5fe6f9e5faca.
Julia is fast as C & Fortran.

1 Like

I have zero knowledge of Julia, but I want to give it a try, I hope to get it! Thanks for everything @empet

Hi again @empet !
Where can I find the quiver.jl file?

Hi @esia2019

In this notebook https://nbviewer.org/gist/empet/e93943ab1c34501df3812fe35a25429a the lines of code in the first cell, between
#--------------------------------------------------#

#-----------------------------------------------------#,
are the contents of quiver.jl.
You can save quiver.jl either in the same folder as your current notebook, or in a subfolder, say julians,
and import it as:

include("julians/quiver.jl")

This notebook illustrates a few examples to see how different settings lead to different quiver plots.

To install Parameters, in REPL import Pkg:

using Pkg
Pkg.add("Parameters")

Good luck!! :slight_smile: