简体   繁体   English

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

[英]How to change color of line of an arrow in bokeh?

I want to draw an arrow between two points on a map using bokeh. 我想使用散景在地图上的两个点之间绘制箭头。 I was able to do that with following code. 我可以使用以下代码做到这一点。 I am able to change the color of arrow but not the color of line or the type of line dash. 我可以更改箭头的颜色,但不能更改线的颜色或破折号的类型。 Looks like the properties exist only for the head. 看起来属性仅存在于头部。 Is there a property to change color of the line and the line dash type (or) an alternate method to achieve the same? 是否具有更改线条颜色和虚线样式的属性(或)以实现相同的替代方法?

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) 

产量

bokeh version - 1.0.2 散景版本-1.0.2

You have passed a line_color to OpenHead . 您已将line_color传递给OpenHead If you want to change the color of the arrow shaft, you also need to pass line_color to Arrow as well. 如果要更改箭头杆的颜色,还需要将line_color传递给Arrow They are distinct components, each with their own separate configuration. 它们是不同的组件,每个都有各自独立的配置。 Same comment applies to line_dash . 同样的注释适用于line_dash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM