如何更改散景中箭头线的颜色?

时间:2019-05-13 21:14:44

标签: python bokeh

我想使用bokeh在地图上的两个点之间绘制箭头。我可以使用以下代码做到这一点。我可以更改箭头的颜色,但不能更改线的颜色或破折号的类型。看起来属性仅存在于头部。是否具有更改线条颜色和虚线样式的属性(或)以实现相同的替代方法?

from bokeh.plotting import figure, show, save
from bokeh.models import (Arrow, OpenHead)
from bokeh.io import curdoc, output_notebook, output_file, export_png
from bokeh.tile_providers import CARTODBPOSITRON_RETINA
from pyproj import Proj, transform

def latlonrange(lat1,lon1,lat2,lon2):
    p1 = Proj(init='epsg:4326')
    p2 = Proj(init='epsg:3857')    
    x1, y1 = transform(p1,p2,lon1,lat1)
    x2, y2 = transform(p1,p2,lon2,lat2)
    return {"x_range":(x1, x2), "y_range":(y1,y2)}   
def to_mercx(lat,lon):
    p1 = Proj(init='epsg:4326')
    p2 = Proj(init='epsg:3857')    
    x, y = transform(p1,p2,lon,lat)
    return x
def to_mercy(lat,lon):
    p1 = Proj(init='epsg:4326')
    p2 = Proj(init='epsg:3857')    
    x, y = transform(p1,p2,lon,lat)
    return y

curdoc().clear()
latlonbox = latlonrange(49.54, -127.28, 23.15, -66.24)
output_notebook()

p = figure(title="Map",
           x_range=latlonbox["x_range"], y_range=latlonbox["y_range"],
           x_axis_type="mercator", y_axis_type="mercator",
           plot_width=1280, plot_height=800,
           tools="pan,wheel_zoom,box_zoom,reset,zoom_in,zoom_out,save",
           output_backend="webgl")
p.add_tile(CARTODBPOSITRON_RETINA)

p.add_layout(Arrow(end=OpenHead(line_color="#a4225f", size=10, line_width=1),
                   x_start=-9416152.41, y_start=3994480.89, x_end=-9166023.45, y_end=3242606.81))

show(p) 

Output

散景版本-1.0.2

1 个答案:

答案 0 :(得分:1)

您已将line_color传递给OpenHead。如果要更改箭头轴的​​颜色,还需要将line_color传递给Arrow。它们是不同的组件,每个都有各自独立的配置。相同的评论适用于line_dash