Travel Tips
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
图表辅助参数设置 辅助标注、注释、矢量箭头
辅助标注、注释、矢量箭头
参考官方文档:https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#color-bars
import numpy as np import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import warnings warnings.filterwarnings('ignore') # 不发出警告 from bokeh.io import output_notebook output_notebook() # 导入notebook绘图模块 from bokeh.plotting import figure,show # 导入图表绘制、图标展示模块
from bokeh.models.annotations import Span # 导入Span模块 x = np.linspace(0, 20, 200) y = np.sin(x) # 创建x,y数据 p = figure(y_range=(-2, 2)) p.line(x, y) # 绘制曲线 upper = Span(location=1, # 设置位置,对应坐标值 dimension='width', # 设置方向,width为横向,height为纵向 line_color='olive', line_width=4, line_dash=[8,4] # 设置线颜色、线宽 ) p.add_layout(upper) # 绘制辅助线1 lower = Span(location=-1, dimension='width', line_color='firebrick', line_width=4) p.add_layout(lower) # 绘制辅助线2 show(p)
from bokeh.models.annotations import BoxAnnotation # 导入BoxAnnotation模块 x = np.linspace(0, 20, 200) y = np.sin(x) # 创建x,y数据 p = figure(y_range=(-2, 2)) p.line(x, y) # 绘制曲线 upper = BoxAnnotation(bottom=1, fill_alpha=0.1, fill_color='olive') p.add_layout(upper) # 绘制辅助矩形1 lower = BoxAnnotation(top=-1, fill_alpha=0.1, fill_color='firebrick') p.add_layout(lower) # 绘制辅助矩形2 center = BoxAnnotation(top=0.6, bottom=-0.3, left=7, right=12, # 设置矩形四边位置 fill_alpha=0.1, fill_color='navy',line_dash=[6,2], line_color='red' # 设置透明度、颜色 ) p.add_layout(center) # 绘制辅助矩形3 show(p)
from bokeh.models.annotations import Label # 导入Label模块,注意是annotations中的Label p = figure(x_range=(0,10), y_range=(0,10)) p.circle([2, 5, 8], [4, 7, 6], color="olive", size=10) # 绘制散点图 label = Label(x=5, y=7, # 标注注释位置 x_offset=12, # x偏移,同理y_offset text="Second Point", # 注释内容 text_font_size="12pt", # 字体大小 border_line_color="red", background_fill_color="gray", background_fill_alpha = 0.5 # 背景线条颜色、背景颜色、透明度 ) 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=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), # 设置箭头类型,及相关参数:OpenHead, NormalHead, VeeHead x_start=0, y_start=0, x_end=1, y_end=0)) # 设置箭头矢量方向 # 绘制箭头1 p.add_layout(Arrow(end=NormalHead(fill_color="orange"), x_start=1, y_start=0, x_end=0.5, y_end=0.7)) # 绘制箭头2 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)) # 绘制箭头3 show(p)
# 调色盘 # 颜色参考文档:http://bokeh.pydata.org/en/latest/docs/reference/palettes.html # ColorBrewer:http://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3 import bokeh.palettes as bp from bokeh.palettes import brewer print('所有调色板名称:\n',bp.__palettes__) print('-------') # 查看所有调色板名称 print('蓝色调色盘颜色:\n',bp.Blues) print('-------') # 查看蓝色调色盘颜色 n = 8 colori = brewer['YlGn'][n] print('YlGn调色盘解析为%i个颜色,分别为:\n' % n, colori) # 调色盘解析 → 不同颜色解析最多颜色有限
所有调色板名称: ['Accent3', 'Accent4', 'Accent5', 'Accent6', 'Accent7', 'Accent8', 'Blues3', 'Blues4', 'Blues5', 'Blues6', 'Blues7', 'Blues8', 'Blues9', 'Blues256', 'BrBG3', 'BrBG4', 'BrBG5', 'BrBG6', 'BrBG7', 'BrBG8', 'BrBG9', 'BrBG10', 'BrBG11', 'BuGn3', 'BuGn4', 'BuGn5', 'BuGn6', 'BuGn7', 'BuGn8', 'BuGn9', 'BuPu3', 'BuPu4', 'BuPu5', 'BuPu6', 'BuPu7', 'BuPu8', 'BuPu9', 'Category10_3', 'Category10_4', 'Category10_5', 'Category10_6', 'Category10_7', 'Category10_8', 'Category10_9', 'Category10_10', 'Category20_3', 'Category20_4', 'Category20_5', 'Category20_6', 'Category20_7', 'Category20_8', 'Category20_9', 'Category20_10', 'Category20_11', 'Category20_12', 'Category20_13', 'Category20_14', 'Category20_15', 'Category20_16', 'Category20_17', 'Category20_18', 'Category20_19', 'Category20_20', 'Category20b3', 'Category20b4', 'Category20b5', 'Category20b6', 'Category20b7', 'Category20b8', 'Category20b9', 'Category20b10', 'Category20b11', 'Category20b12', 'Category20b13', 'Category20b14', 'Category20b15', 'Category20b16', 'Category20b17', 'Category20b18', 'Category20b19', 'Category20b20', 'Category20c3', 'Category20c4', 'Category20c5', 'Category20c6', 'Category20c7', 'Category20c8', 'Category20c9', 'Category20c10', 'Category20c11', 'Category20c12', 'Category20c13', 'Category20c14', 'Category20c15', 'Category20c16', 'Category20c17', 'Category20c18', 'Category20c19', 'Category20c20', 'Cividis3', 'Cividis4', 'Cividis5', 'Cividis6', 'Cividis7', 'Cividis8', 'Cividis9', 'Cividis10', 'Cividis11', 'Cividis256', 'Colorblind3', 'Colorblind4', 'Colorblind5', 'Colorblind6', 'Colorblind7', 'Colorblind8', 'Dark2_3', 'Dark2_4', 'Dark2_5', 'Dark2_6', 'Dark2_7', 'Dark2_8', 'GnBu3', 'GnBu4', 'GnBu5', 'GnBu6', 'GnBu7', 'GnBu8', 'GnBu9', 'Greens3', 'Greens4', 'Greens5', 'Greens6', 'Greens7', 'Greens8', 'Greens9', 'Greens256', 'Greys3', 'Greys4', 'Greys5', 'Greys6', 'Greys7', 'Greys8', 'Greys9', 'Greys256', 'Inferno3', 'Inferno4', 'Inferno5', 'Inferno6', 'Inferno7', 'Inferno8', 'Inferno9', 'Inferno10', 'Inferno11', 'Inferno256', 'Magma3', 'Magma4', 'Magma5', 'Magma6', 'Magma7', 'Magma8', 'Magma9', 'Magma10', 'Magma11', 'Magma256', 'OrRd3', 'OrRd4', 'OrRd5', 'OrRd6', 'OrRd7', 'OrRd8', 'OrRd9', 'Oranges3', 'Oranges4', 'Oranges5', 'Oranges6', 'Oranges7', 'Oranges8', 'Oranges9', 'Oranges256', 'PRGn3', 'PRGn4', 'PRGn5', 'PRGn6', 'PRGn7', 'PRGn8', 'PRGn9', 'PRGn10', 'PRGn11', 'Paired3', 'Paired4', 'Paired5', 'Paired6', 'Paired7', 'Paired8', 'Paired9', 'Paired10', 'Paired11', 'Paired12', 'Pastel1_3', 'Pastel1_4', 'Pastel1_5', 'Pastel1_6', 'Pastel1_7', 'Pastel1_8', 'Pastel1_9', 'Pastel2_3', 'Pastel2_4', 'Pastel2_5', 'Pastel2_6', 'Pastel2_7', 'Pastel2_8', 'PiYG3', 'PiYG4', 'PiYG5', 'PiYG6', 'PiYG7', 'PiYG8', 'PiYG9', 'PiYG10', 'PiYG11', 'Plasma3', 'Plasma4', 'Plasma5', 'Plasma6', 'Plasma7', 'Plasma8', 'Plasma9', 'Plasma10', 'Plasma11', 'Plasma256', 'PuBu3', 'PuBu4', 'PuBu5', 'PuBu6', 'PuBu7', 'PuBu8', 'PuBu9', 'PuBuGn3', 'PuBuGn4', 'PuBuGn5', 'PuBuGn6', 'PuBuGn7', 'PuBuGn8', 'PuBuGn9', 'PuOr3', 'PuOr4', 'PuOr5', 'PuOr6', 'PuOr7', 'PuOr8', 'PuOr9', 'PuOr10', 'PuOr11', 'PuRd3', 'PuRd4', 'PuRd5', 'PuRd6', 'PuRd7', 'PuRd8', 'PuRd9', 'Purples3', 'Purples4', 'Purples5', 'Purples6', 'Purples7', 'Purples8', 'Purples9', 'Purples256', 'RdBu3', 'RdBu4', 'RdBu5', 'RdBu6', 'RdBu7', 'RdBu8', 'RdBu9', 'RdBu10', 'RdBu11', 'RdGy3', 'RdGy4', 'RdGy5', 'RdGy6', 'RdGy7', 'RdGy8', 'RdGy9', 'RdGy10', 'RdGy11', 'RdPu3', 'RdPu4', 'RdPu5', 'RdPu6', 'RdPu7', 'RdPu8', 'RdPu9', 'RdYlBu3', 'RdYlBu4', 'RdYlBu5', 'RdYlBu6', 'RdYlBu7', 'RdYlBu8', 'RdYlBu9', 'RdYlBu10', 'RdYlBu11', 'RdYlGn3', 'RdYlGn4', 'RdYlGn5', 'RdYlGn6', 'RdYlGn7', 'RdYlGn8', 'RdYlGn9', 'RdYlGn10', 'RdYlGn11', 'Reds3', 'Reds4', 'Reds5', 'Reds6', 'Reds7', 'Reds8', 'Reds9', 'Reds256', 'Set1_3', 'Set1_4', 'Set1_5', 'Set1_6', 'Set1_7', 'Set1_8', 'Set1_9', 'Set2_3', 'Set2_4', 'Set2_5', 'Set2_6', 'Set2_7', 'Set2_8', 'Set3_3', 'Set3_4', 'Set3_5', 'Set3_6', 'Set3_7', 'Set3_8', 'Set3_9', 'Set3_10', 'Set3_11', 'Set3_12', 'Spectral3', 'Spectral4', 'Spectral5', 'Spectral6', 'Spectral7', 'Spectral8', 'Spectral9', 'Spectral10', 'Spectral11', 'Turbo3', 'Turbo4', 'Turbo5', 'Turbo6', 'Turbo7', 'Turbo8', 'Turbo9', 'Turbo10', 'Turbo11', 'Turbo256', 'Viridis3', 'Viridis4', 'Viridis5', 'Viridis6', 'Viridis7', 'Viridis8', 'Viridis9', 'Viridis10', 'Viridis11', 'Viridis256', 'YlGn3', 'YlGn4', 'YlGn5', 'YlGn6', 'YlGn7', 'YlGn8', 'YlGn9', 'YlGnBu3', 'YlGnBu4', 'YlGnBu5', 'YlGnBu6', 'YlGnBu7', 'YlGnBu8', 'YlGnBu9', 'YlOrBr3', 'YlOrBr4', 'YlOrBr5', 'YlOrBr6', 'YlOrBr7', 'YlOrBr8', 'YlOrBr9', 'YlOrRd3', 'YlOrRd4', 'YlOrRd5', 'YlOrRd6', 'YlOrRd7', 'YlOrRd8', 'YlOrRd9'] ------- 蓝色调色盘颜色: {3: ('#3182bd', '#9ecae1', '#deebf7'), 4: ('#2171b5', '#6baed6', '#bdd7e7', '#eff3ff'), 5: ('#08519c', '#3182bd', '#6baed6', '#bdd7e7', '#eff3ff'), 6: ('#08519c', '#3182bd', '#6baed6', '#9ecae1', '#c6dbef', '#eff3ff'), 7: ('#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#eff3ff'), 8: ('#084594', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff'), 9: ('#08306b', '#08519c', '#2171b5', '#4292c6', '#6baed6', '#9ecae1', '#c6dbef', '#deebf7', '#f7fbff'), 256: ('#08306b', '#08316d', '#08326e', '#083370', '#083471', '#083573', '#083674', '#083776', '#083877', '#083979', '#083a7a', '#083b7c', '#083c7d', '#083d7f', '#083e81', '#084082', '#084184', '#084285', '#084387', '#084488', '#08458a', '#08468b', '#08478d', '#08488e', '#084990', '#084a91', '#084b93', '#084c95', '#084d96', '#084e98', '#084f99', '#08509b', '#08519c', '#09529d', '#0a539e', '#0a549e', '#0b559f', '#0c56a0', '#0d57a1', '#0e58a2', '#0e59a2', '#0f5aa3', '#105ba4', '#115ca5', '#125da6', '#125ea6', '#135fa7', '#1460a8', '#1561a9', '#1562a9', '#1663aa', '#1764ab', '#1865ac', '#1966ad', '#1967ad', '#1a68ae', '#1b69af', '#1c6ab0', '#1c6bb0', '#1d6cb1', '#1e6db2', '#1f6eb3', '#206fb4', '#2070b4', '#2171b5', '#2272b6', '#2373b6', '#2474b7', '#2575b7', '#2676b8', '#2777b8', '#2979b9', '#2a7ab9', '#2b7bba', '#2c7cba', '#2d7dbb', '#2e7ebc', '#2f7fbc', '#3080bd', '#3181bd', '#3282be', '#3383be', '#3484bf', '#3585bf', '#3686c0', '#3787c0', '#3888c1', '#3989c1', '#3a8ac2', '#3b8bc2', '#3c8cc3', '#3d8dc4', '#3e8ec4', '#3f8fc5', '#4090c5', '#4191c6', '#4292c6', '#4493c7', '#4594c7', '#4695c8', '#4896c8', '#4997c9', '#4a98c9', '#4b98ca', '#4d99ca', '#4e9acb', '#4f9bcb', '#519ccc', '#529dcc', '#539ecd', '#549fcd', '#56a0ce', '#57a0ce', '#58a1cf', '#5aa2cf', '#5ba3d0', '#5ca4d0', '#5da5d1', '#5fa6d1', '#60a7d2', '#61a7d2', '#63a8d3', '#64a9d3', '#65aad4', '#66abd4', '#68acd5', '#69add5', '#6aaed6', '#6caed6', '#6dafd7', '#6fb0d7', '#71b1d7', '#72b2d8', '#74b3d8', '#75b4d8', '#77b5d9', '#79b5d9', '#7ab6d9', '#7cb7da', '#7db8da', '#7fb9da', '#81badb', '#82bbdb', '#84bcdb', '#85bcdc', '#87bddc', '#89bedc', '#8abfdd', '#8cc0dd', '#8dc1dd', '#8fc2de', '#91c3de', '#92c4de', '#94c4df', '#95c5df', '#97c6df', '#99c7e0', '#9ac8e0', '#9cc9e1', '#9dcae1', '#9fcae1', '#a0cbe2', '#a1cbe2', '#a3cce3', '#a4cce3', '#a5cde3', '#a6cee4', '#a8cee4', '#a9cfe5', '#aacfe5', '#abd0e6', '#add0e6', '#aed1e7', '#afd1e7', '#b0d2e7', '#b2d2e8', '#b3d3e8', '#b4d3e9', '#b5d4e9', '#b7d4ea', '#b8d5ea', '#b9d6ea', '#bad6eb', '#bcd7eb', '#bdd7ec', '#bed8ec', '#bfd8ed', '#c1d9ed', '#c2d9ee', '#c3daee', '#c4daee', '#c6dbef', '#c7dbef', '#c7dcef', '#c8dcf0', '#c9ddf0', '#caddf0', '#cadef0', '#cbdef1', '#ccdff1', '#cddff1', '#cde0f1', '#cee0f2', '#cfe1f2', '#d0e1f2', '#d0e2f2', '#d1e2f3', '#d2e3f3', '#d3e3f3', '#d3e4f3', '#d4e4f4', '#d5e5f4', '#d6e5f4', '#d6e6f4', '#d7e6f5', '#d8e7f5', '#d9e7f5', '#d9e8f5', '#dae8f6', '#dbe9f6', '#dce9f6', '#dceaf6', '#ddeaf7', '#deebf7', '#dfebf7', '#dfecf7', '#e0ecf8', '#e1edf8', '#e2edf8', '#e3eef8', '#e3eef9', '#e4eff9', '#e5eff9', '#e6f0f9', '#e7f0fa', '#e7f1fa', '#e8f1fa', '#e9f2fa', '#eaf2fb', '#eaf3fb', '#ebf3fb', '#ecf4fb', '#edf4fc', '#eef5fc', '#eef5fc', '#eff6fc', '#f0f6fd', '#f1f7fd', '#f2f7fd', '#f2f8fd', '#f3f8fe', '#f4f9fe', '#f5f9fe', '#f5fafe', '#f6faff', '#f7fbff')} ------- YlGn调色盘解析为8个颜色,分别为: ('#005a32', '#238443', '#41ab5d', '#78c679', '#addd8e', '#d9f0a3', '#f7fcb9', '#ffffe5')
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Sed ac lorem felis. Ut in odio lorem. Quisque magna dui, maximus ut commodo sed, vestibulum ac nibh. Aenean a tortor in sem tempus auctor
December 4, 2020 at 3:12 pm
Donec in ullamcorper quam. Aenean vel nibh eu magna gravida fermentum. Praesent eget nisi pulvinar, sollicitudin eros vitae, tristique odio.
December 4, 2020 at 3:12 pm
我是 s enim interduante quis metus. Duis porta ornare nulla ut bibendum
Rosie
6 minutes ago