Example #1
0
def test_Arrow():
    arrow = Arrow()
    assert arrow.plot is None
    assert arrow.x_start is None
    assert arrow.y_start is None
    assert arrow.start_units == 'data'
    assert arrow.start is None
    assert arrow.x_end is None
    assert arrow.y_end is None
    assert arrow.end_units == 'data'
    assert isinstance(arrow.end, ArrowHead)
    assert arrow.source is None
    assert arrow.x_range_name == "default"
    assert arrow.y_range_name == "default"
    yield check_line, arrow
    yield (check_props, arrow, [
        "plot",
        "level",
        "x_start",
        "y_start",
        "start_units",
        "start",
        "x_end",
        "y_end",
        "end_units",
        "end",
        "source",
        "x_range_name",
        "y_range_name"],
        LINE)
def test_Arrow():
    arrow = Arrow()
    assert arrow.plot is None
    assert arrow.x_start is None
    assert arrow.y_start is None
    assert arrow.start_units == 'data'
    assert arrow.start is None
    assert arrow.x_end is None
    assert arrow.y_end is None
    assert arrow.end_units == 'data'
    assert isinstance(arrow.end, ArrowHead)
    assert arrow.source is None
    assert arrow.x_range_name == "default"
    assert arrow.y_range_name == "default"
    check_line_properties(arrow)
    check_properties_existence(arrow, [
        "plot",
        "level",
        "visible",
        "x_start",
        "y_start",
        "start_units",
        "start",
        "x_end",
        "y_end",
        "end_units",
        "end",
        "source",
        "x_range_name",
        "y_range_name"],
        LINE)
Example #3
0
def add_ascending_node_direction(plot):
    plot.add_layout(
        Arrow(
            end=VeeHead(
                size=10,
                fill_color=colors["ascending-node"],
                line_color=colors["ascending-node"],
            ),
            line_width=3,
            x_start=0,
            y_start=0,
            x_end=constants.PLOTS_RANGE,
            y_end=0,
            line_color=colors["ascending-node"],
        )
    )
    plot.add_layout(
        Label(
            text="Ascending Node",
            x=0.5 * constants.PLOTS_RANGE,
            y=-0.1 * constants.PLOTS_RANGE,
            text_font_size="8pt",
            text_color=colors["ascending-node"],
        )
    )
Example #4
0
def add_vernal_direction(plot):
    plot.add_layout(
        Arrow(
            end=VeeHead(
                size=10, fill_color=colors["vernal"], line_color=colors["vernal"]
            ),
            line_width=3,
            x_start=0,
            y_start=0,
            x_end=constants.PLOTS_RANGE,
            y_end=0,
            line_color=colors["vernal"],
        )
    )
    plot.add_layout(
        Label(
            text="Vernal Equinox",
            x=0.5 * constants.PLOTS_RANGE,
            y=-0.1 * constants.PLOTS_RANGE,
            text_font_size="8pt",
            text_color=colors["vernal"],
        )
    )
Example #5
0
def add_north_direction(plot):
    plot.add_layout(
        Arrow(
            end=VeeHead(
                size=10, fill_color=colors["north"], line_color=colors["north"]
            ),
            line_width=3,
            x_start=0,
            y_start=0,
            x_end=0,
            y_end=constants.PLOTS_RANGE,
            line_color=colors["north"],
        )
    )
    plot.add_layout(
        Label(
            text="North",
            x=0.05 * constants.PLOTS_RANGE,
            y=0.8 * constants.PLOTS_RANGE,
            text_font_size="8pt",
            text_color=colors["north"],
        )
    )
Example #6
0
eegbrow.update()

# %%

# %%

# %%

# %%
# experiment with more anotations, need to add a scale bar
import bokeh
from bokeh.models.annotations import BoxAnnotation, Arrow
t = eegbrow.loc_sec - eegbrow.page_width_seconds / 2.0
#scalbox = BoxAnnotation(left=t, right=t+0.5, top=500.0, bottom=0, fill_color='gray', fill_alpha=0.5)
#eegbrow.fig.add_layout(scalbox)
arwV = Arrow(x_start=t, x_end=t, y_start=0, y_end=500.0,
             end=None)  # don't draw an arrow head
arwH = Arrow(x_start=t, x_end=t + 0.5, y_start=0, y_end=0, end=None)
eegbrow.fig.add_layout(arwV)
eegbrow.fig.add_layout(arwH)
eegbrow.push_notebook()

# %%
arwV.x_start = 1384.0
arwV.x_end = 1384.0
eegbrow.push_notebook()

# %%
r = eegbrow.fig.renderers
arrowrend = [ii for ii in r if ii.__class__ == bokeh.models.annotations.Arrow]
a0 = arrowrend[0]
a0.x_end
                                        'y': [4, 7, 5, 5, 9, 2, 3, 4, 3, 4]})

# plot
fig_with_label = figure()
fig_with_label.line(x='x', y='y', source=fig_with_label_data)

# add label
label = Label(x=4, y=9, x_offset=10, text='Higest Point', text_baseline='middle')
fig_with_label.add_layout(label)

# add multiple labels
labels = LabelSet(x='x', y='y', text='y', level='glyph', source=fig_with_label_data)
fig_with_label.add_layout(labels)

# arrow annotation
fig_with_label.add_layout(Arrow(end=NormalHead(fill_color='orange'), x_start=5, y_start=7.5, x_end=4.5, y_end=8.8))

show(fig_with_label)
Loading BokehJS ...
Color Bar
In [79]:
cars.head()
Out[79]:
Acceleration	Cylinders	Displacement	Horsepower	Miles_per_Gallon	Name	Origin	Weight_in_lbs	Year
0	12.0	8	307.0	130.0	18.0	chevrolet chevelle malibu	USA	3504	1970-01-01
1	11.5	8	350.0	165.0	15.0	buick skylark 320	USA	3693	1970-01-01
2	11.0	8	318.0	150.0	18.0	plymouth satellite	USA	3436	1970-01-01
3	12.0	8	304.0	150.0	16.0	amc rebel sst	USA	3433	1970-01-01
4	10.5	8	302.0	140.0	17.0	ford torino	USA	3449	1970-01-01
In [80]:
from bokeh.models import LinearColorMapper, ColorBar
Example #8
0
              border_line_color="red",  # 背景线条颜色
              background_fill_color="gray",  # 背景颜色
              background_fill_alpha = 0.5,   # 透明度
              border_line_dash=[6,4]
             )
p.add_layout(label)

# 显示
show(p)


''' 箭头 '''
from bokeh.models.annotations import Arrow
from bokeh.models.arrow_heads import OpenHead, NormalHead, VeeHead   # 三种箭头类型

# 绘制散点图
p = figure(plot_width=300, plot_height=300)
p.circle(x=[0, 1, 0.5], y=[0, 0, 0.7], radius=0.05, color=["green", "blue", "red"], fill_alpha=0.1)

# 绘制箭头1
p.add_layout(Arrow(end=OpenHead(line_color="firebrick", line_width=4), # 箭头类型,及相关参数:OpenHead, NormalHead, VeeHead
                   x_start=0, y_start=0, x_end=1, y_end=0))  # 设置箭头矢量方向
# 绘制箭头2
p.add_layout(Arrow(end=NormalHead(fill_color="orange"),
                   x_start=1, y_start=0, x_end=0.5, y_end=0.7))
# 绘制箭头3
p.add_layout(Arrow(end=VeeHead(size=35), line_color="red",
                   x_start=0.5, y_start=0.7, x_end=0, y_end=0))

# 显示
show(p)