Thêm chú thích

Trực quan hóa dữ liệu tương tác với Bokeh

George Boorman

Core Curriculum Manager, DataCamp

Chú thích hộp

chú thích hộp

Trực quan hóa dữ liệu tương tác với Bokeh

Thêm chú thích hộp

from bokeh.models import BoxAnnotation
fig = figure(x_axis_label="Rebounds", y_axis_label="Points", title="Points vs. Rebounds")
fig.circle(x="rebounds", y="points", source=source)

low_box = BoxAnnotation(top=10, fill_color="red", fill_alpha=0.3)
mid_box = BoxAnnotation(bottom=10, top=20, fill_color="orange", fill_alpha=0.3)
high_box = BoxAnnotation(bottom=20, fill_color="green", fill_alpha=0.3)
fig.add_layout(low_box) fig.add_layout(mid_box) fig.add_layout(high_box)
fig.title.align = "center" output_file("color_annotated_plot.html") show(fig)
Trực quan hóa dữ liệu tương tác với Bokeh

Chú thích đa giác

chú thích đa giác

Trực quan hóa dữ liệu tương tác với Bokeh

Thêm chú thích đa giác

import datetime as dt
from bokeh.models import PolyAnnotation
fig = figure(title="Nvidia Stock Price", x_axis_label="Date", y_axis_label="Price")
fig.line(x="date", y="close", source=source)
fig.xaxis[0].formatter = DatetimeTickFormatter(months="%b %Y")
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0")

start_date = dt.datetime(2017, 5, 9) end_date = dt.datetime(2017, 6, 12)
start_float = start_date.timestamp() * 1000 end_float = end_date.timestamp() * 1000
start_data = nvidia.loc[nvidia['date'] == start_date]['close'].values[0] end_data = nvidia.loc[nvidia['date'] == end_date]['close'].values[0]
polygon = PolyAnnotation(fill_color="green", fill_alpha=0.4,
xs = [start_float, start_float, end_float, end_float],
ys = [start_data-8, start_data+28, end_data+20, end_data-10])
fig.add_layout(polygon) output_file(filename="nvidia_polygon_annotation.html") show(fig)
Trực quan hóa dữ liệu tương tác với Bokeh

Hãy thực hành!

Trực quan hóa dữ liệu tương tác với Bokeh

Preparing Video For Download...