Curved Arrows

I’m working on the visualisation of internal forces inside an element and I’m enjoying a lot the Bokeh package and I thank you for the great work. For the representation of forces, your Arrow model works perfectly but I’m having some problems representing the bending moment (a curved arrow). Will you implement it? There is already a way to draw it?

In the worst case scenario, I was thinking to draw it manually (patch for the head and line with the function of a semi-circle), but I’m asking to the community because probably I’m not the first person encountering this challenge (and surely not the last one).

Thank you very much.

Arrows are currently very simple annotations with a straight-line shaft between start/end points, and furthermore, the assumption that the arrowheads are angled along this line’s direction is baked in to the source code. We would probably need to add a new model, PathArrow or Pointer or something for this, and also figure out some questions like how to orient arrow heads when the path is curved. I can’t find a relevant existing discussion so I’d suggest you open a GitHub Issue to propose this feature.

1 Like

Overkill here, but as a workaround you could make a spiral and a directional arrow basically leveraging polar coords and the equation r=theta:

from bokeh.plotting import figure,show,save
from bokeh.models import ColumnDataSource, Line, Scatter
import numpy as np

#making a spiral

#starting and ending radius
rmin = 1
rmax = 2
#"how many times to go around (360 deg = 2pi rad)
m = 2*np.pi

#100 length array populating radius and theta
rs = np.linspace(rmin,rmax,100)
ts = np.linspace(m*rmin,m*rmax,100)
#get these arrays out of polar coords 
xs = rs*np.cos(ts)
ys = rs*np.sin(ts)

f = figure()
r = f.line(x=xs,y=ys)
#make a directional marker using last coords
#final theta (aka last item in ts) will dictate orientation of marker for arrow
o = ts[-1]
t = f.scatter(x=[xs[-1]],y=[ys[-1]],marker='triangle',size=15,angle=o)
show(f)

3 Likes

Nice workaround! I am never not amazed by the ingenuity of our users :smiley:

3 Likes

Thank you very much, this is will do the trick. I also crated the GitHub issue as requested [FEATURE] Curved Arrow · Issue #12072 · bokeh/bokeh · GitHub

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.