Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No ability to make true quiver plots #8129

Open
jasonsross opened this issue Aug 2, 2018 · 5 comments · May be fixed by #13619
Open

No ability to make true quiver plots #8129

jasonsross opened this issue Aug 2, 2018 · 5 comments · May be fixed by #13619
Labels
grant: SDG 2023 Funded from NumFOCUS Small Development Grant 2023 tag: component: bokehjs type: feature
Milestone

Comments

@jasonsross
Copy link
Contributor

jasonsross commented Aug 2, 2018

So this is an issue that has come up before, such as #977. In #177 arrow annotations were implemented to draw arrows but I do not think that addresses the request for true quiver/vector plots.

Currently there is a gallery called quiver.py on the Bokeh welcome page that shows some flow graphs here but I do not consider this a quiver plot (or a vector field) because we do not see the directionality of the segments, They need an arrow pointing out from one of their end caps.

Below I show a python example that graphs a vector field in matplotlib and gets close with Bokeh. Notice matplotlib's quiver plotter generates arrows at each point showing direction of the field. Plotly also has a quiver plotter function seen here.

But with Bokeh, the closest we can do is use segments. If you run my example, you can see how the Bokeh plot does not help us learn which direction the flow is in, we just see the contour of the flow.

I think implementing this feature will draw in a lot more academics and other users that work with vector fields. Directionality is important as one needs to know if their grid is say shrinking vs expanding.

Here's a couple suggestions for implementation:

  1. Add a boolean parameter to the segment glyph called arrow_cap which will turn on an arrow end cap (at x1, y1 pointing out from the segment) for all segments drawn. The size of the arrow will of course need to scale with the line_width of the segment

  2. Create a new glyph called quiver that's similar to segment but obviously with one cap being an arrow and the other cap being standard controlled by line_cap. This glyph could implement some automated scaling features and also expect the vector-field standard x, y, u, v data format (where u are v are the deviations at each x, y coordinate) like matplotlib's quiver does. Notice how it took a little more work with segment in my code to get it plotting the data like matplotlib.

Thanks for reading. Hope this was enough info.

import matplotlib.pyplot as plt
from bokeh.plotting import figure, curdoc
from bokeh.io import output_file, show
import numpy as np

#create grid then flatten arrays into columns for graphing methods
x, y = np.meshgrid(np.linspace(-10,10,30),np.linspace(-10,10,30))
x = x.ravel()
y = y.ravel()

#create some fun patterns for the deviations (u,v) at each grid point
u = 1/y
v = np.sin(x/5)

# matplotlib quiver plot
fig = plt.figure(figsize = (6,6))
plt.quiver(x,y,u,v)
plt.show()

# get and clear curdoc so can run script multiple times from current python session
doc = curdoc()
doc.clear()

p = figure()
factor = 1/2
p.segment(x, y,
          x + factor * u,
          y + factor * v,
          line_cap = 'round',
          line_width = 4)
output_file('quiver_test.html')
show(p)

@jbednar
Copy link
Contributor

jbednar commented Aug 2, 2018

You can try http://holoviews.org/reference/elements/bokeh/VectorField.html if using HoloViews to generate the Bokeh figure is an option for you (and the HoloViews source code, if it isn't).

@jasonsross
Copy link
Contributor Author

Any thoughts on this so far? How difficult would it be to upgrade the segments to have different styled endcaps on each end and/or added an arrow shaped endcap?

As @jbednar pointed out, holoviews figured out how to get Bokeh to plot these but I would prefer to stick with core Bokeh coding because my organization uses Anaconda which doesn't include HoloViews currently and getting my peers to manage their packages outside of Anaconda distribution can be frustrating.

@bryevdv
Copy link
Member

bryevdv commented Aug 22, 2018

The (2) core devs are underwater with other tasks right now. I can't speculate when this might be able to be prioritized. For now, I would suggest e.g. plotting circle a circle at one end to indicate a "base" for a quiver, or angle information is readily available, plotting a rotated, narrow diamond at the other end to indicate a "tip". Or you could use ArrowHead manually, for that matter. It is slightly odd because arrow heads are technically considered an annotation, not a glyph, but that doesn't have any implications for the visual look. (I'm guessing this might be what HoloViews does, and as @jbednar mentioned, you can always refer to the HV source code to see what they do)

@jbednar
Copy link
Contributor

jbednar commented Aug 22, 2018

I believe the Anaconda Distribution is selected from the packages available on the "defaults" conda channel, where HoloViews is already available, so you could also try making a request that it be added into the distribution. Not sure how likely that is, but it might be easier than having to replicate this functionality yourself and/or get it to appear in an official Bokeh release that then becomes part of a subsequent Distribution release...

@eromoe
Copy link

eromoe commented Apr 10, 2020

As I see, there is no issue finished in short-term milestone ...
How is this going on ?

@mattpap mattpap linked a pull request Dec 24, 2023 that will close this issue
@mattpap mattpap modified the milestones: short-term, 3.4 Dec 24, 2023
@mattpap mattpap added the grant: SDG 2023 Funded from NumFOCUS Small Development Grant 2023 label Dec 24, 2023
@mattpap mattpap modified the milestones: 3.4, 3.5 Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
grant: SDG 2023 Funded from NumFOCUS Small Development Grant 2023 tag: component: bokehjs type: feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants