Bokeh 添加注释

xiaoxiao2021-02-28  92

http://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html

Titles(标题)

添加标题

from bokeh.plotting import figure, show, output_file p = figure(title="Basic Title", plot_width=300, plot_height=300) p.circle([1,2], [3,4]) output_file("title.html") show(p)

设置标题属性

from bokeh.plotting import figure, show, output_file p = figure(plot_width=300, plot_height=300) p.circle([1,2], [3,4]) # configure visual properties on a plot's title attribute p.title.text = "Title With Options" p.title.align = "right" p.title.text_color = "orange" p.title.text_font_size = "25px" p.title.background_fill_color = "#aaaaee" output_file("title.html") show(p)

Legends

import numpy as np from bokeh.plotting import output_file, show, figure x = np.linspace(0, 4*np.pi, 100) y = np.sin(x) output_file("legend.html") p = figure() p.circle(x, y, legend="sin(x)") p.line(x, y, legend="sin(x)") p.line(x, 2*y, legend="2*sin(x)", line_dash=[4, 4], line_color="orange", line_width=2) p.square(x, 3*y, legend="3*sin(x)", fill_color=None, line_color="green") p.line(x, 3*y, legend="3*sin(x)", line_color="green") show(p)

Color Bars(颜色条)

import numpy as np from matplotlib.mlab import bivariate_normal from bokeh.plotting import figure, output_file, show from bokeh.models import LogColorMapper, LogTicker, ColorBar output_file('color_bar.html') N = 100 X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + \ 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) image = Z1 * 1e6 color_mapper = LogColorMapper(palette="Viridis256", low=1, high=1e7) plot = figure(x_range=(0,1), y_range=(0,1), toolbar_location=None) plot.image(image=[image], color_mapper=color_mapper, dh=[1.0], dw=[1.0], x=[0], y=[0]) color_bar = ColorBar(color_mapper=color_mapper, ticker=LogTicker(), label_standoff=12, border_line_color=None, location=(0,0)) plot.add_layout(color_bar, 'right') show(plot)

Arrows(箭头)

from bokeh.plotting import figure, output_file, show from bokeh.models import Arrow, OpenHead, NormalHead, VeeHead output_file("arrow.html", title="arrow.py example") p = figure(plot_width=600, plot_height=600) p.circle(x=[0, 1, 0.5], y=[0, 0, 0.7], radius=0.1, color=["navy", "yellow", "red"], fill_alpha=0.1) p.add_layout(Arrow(end=OpenHead(line_color="firebrick", line_width=4), x_start=0, y_start=0, x_end=1, y_end=0)) p.add_layout(Arrow(end=NormalHead(fill_color="orange"), x_start=1, y_start=0, x_end=0.5, y_end=0.7)) 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)

Bands

A Band will create a dimensionally-linked “stripe”, either located in data or screen coordinates.

Box Annotations

A BoxAnnotation can be linked to either data or screen coordinates in order to emphasize specific plot regions.

Labels

Labels are text elements that can be used to annotate either glyphs or plot regions.

Spans

Span annotations are lines that have a single dimension (width or height) and extend to the edge of the plot area.

Whiskers

A Whisker will create a dimensionally-linked “stem”, either located in data or screen coordinates.

转载请注明原文地址: https://www.6miu.com/read-60372.html

最新回复(0)