No ability to make true quiver plots
See original GitHub issueSo 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:
-
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
-
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)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:5 (4 by maintainers)
Top GitHub Comments
As I see, there is no issue finished in short-term milestone … How is this going on ?
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…