Skip to content

Vectorized Arrow Heads #6835

@Tunnelvisie

Description

@Tunnelvisie

I posted this in the Bokeh Gmail Group before and Bryan advised to open an issue. So here it is (better late then never):

See my sample code below. I'm drawing a whole bunch of arrows in a plot, all arrows have a line weight (lw), an alpha (a) and an arrow line weight (lw_arrow) -basically the arrow size- and start and end coordinates.

Unfortunately when I feed this information to my plot using source it seems impossible to send the 'a' and 'lw_arrow' into the VeeHead function, and it seems only possible to hard code the variables in VeeHead, as I have done now.

What I would like to do instead is the following: end=VeeHead(fill_color="black", size='lw_arrow', fill_alpha='a', line_alpha='a') where 'lw_arrow' and 'a' are coming from source.

from bokeh.plotting import figure
from bokeh.models import Arrow, VeeHead
from bokeh.models import ColumnDataSource
import pandas as pd
from bokeh.io import curdoc

df = pd.DataFrame(
    {'x1': [48.61416189, 50.76303746, 47.54218554, 46.91226294],
     'y1': [78.99324704, 80.69915616, 79.41805739, 80.28060694],
     'x2': [70.60720053, 67.54310965, 52.38867755, 34.25213619],
     'y2': [52.90955905, 93.23068347, 37.70820205, 52.30176102],
     'lw': [5, 6, 7, 2],
     'a': [1, 1, 0.5, 0.25],
     'lw_arrow': [15, 18, 21, 6],

    })

p = figure(plot_width=600, plot_height=428,
               x_range=[0,100],
               y_range=[0,100],
               logo=None,
               toolbar_location = 'below')


source = ColumnDataSource(data=dict(
        x1=[],
        y1=[],
        x2=[],
        y2=[],
        lw=[],
        a=[],
        lw_arrow=[],

    ))

arrows = Arrow(end=VeeHead(fill_color="black", size=10, fill_alpha=.5, line_alpha=.5),
                   x_start='x1',
                   y_start='y1',
                   x_end='x2',
                   y_end='y2',
                   source=source,
                   line_width='lw',
                   line_alpha='a')

p.add_layout(arrows)

def update():
    """
    update the new graph with the values from selected at select_for_graph by passing it through the source
    :return:
    """

    #for the lines we need the whole dataframe
    source.data = dict(
        x1=df['x1'],
        y1=df['y1'],
        x2=df['x2'],
        y2=df['y2'],
        lw=df['lw'],
        a=df['a'],
        lw_arrow=df['lw_arrow']
    )

curdoc().add_root(p)
curdoc().add_periodic_callback(update,1000)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions