question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No ability to make true quiver plots

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:5
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
eromoecommented, Apr 10, 2020

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

0reactions
jbednarcommented, 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

matplotlib - Python quiver plot without head - Stack Overflow
I'd like to make a quiver plot ...
Read more >
Quiver or vector plot - MATLAB quiver - MathWorks
This MATLAB function plots arrows with directional components U and V at the Cartesian coordinates specified by X and Y.
Read more >
Anyone have a Plots quiver() example? - Julia Discourse
I've just spent a fruitless day looking through Plots, Plot.ly and PyPlot documentation, trying to find a prototype for the (2-D) quiver() diagram...
Read more >
quiver plot on hyperboloid surface - LaTeX Stack Exchange
Asymptote is probably better for this, since it allows for hiding the arrows behind the hyperboloid surface, but here's how you can draw...
Read more >
Scatter plot on polar axis — Matplotlib 3.6.2 documentation
Size increases radially in this example and color increases with angle (just to verify the symbols are being scattered correctly). import numpy as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found