ToolBar工具栏设置

① 位置设置
② 移动、放大缩小、存储、刷新
③ 选择
④ 提示框、十字线

1. 位置设置

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 import ColumnDataSource
# 导入图表绘制、图标展示模块
# 导入ColumnDataSource模块

# 工具栏 tools
# (1)设置位置 p = figure(plot_width=300, plot_height=300,
toolbar_location="above")
# 工具栏位置:"above","below","left","right" p.circle(np.random.randn(100),np.random.randn(100))
show(p)

# 工具栏 tools
# (1)设置位置 p = figure(plot_width=300, plot_height=300,
toolbar_location="below",
toolbar_sticky=False)
# 工具栏位置设置为"below"时,可增加toolbar_sticky参数使得toolsbar不被遮挡
p.circle(np.random.randn(100),np.random.randn(100))
show(p)

2. 移动、放大缩小、存储、刷新

# 工具栏 tools
# (2)移动、放大缩小、存储、刷新 TOOLS = '''
pan, xpan, ypan,
box_zoom,
wheel_zoom, xwheel_zoom, ywheel_zoom,
zoom_in, xzoom_in, yzoom_in,
zoom_out, xzoom_out, yzoom_out,
save,reset
'''
#pan是直接移动;xpan和ypan分别是横轴、竖轴移动;box_zoom是矩形框放大,wheel_zoom滚轮缩放:直接缩放、X轴缩放、Y轴缩放;通过鼠标点击缩放zoom_in
p = figure(plot_width=800, plot_height=400,toolbar_location="above",
tools = TOOLS)
# 添加toolbar
# 这里tools = '' 则不显示toolbar p.circle(np.random.randn(500),np.random.randn(500))
show(p)

3. 选择

# 工具栏 tools
# (3)选择 TOOLS = '''
box_select,lasso_select,
reset
'''
#画多边形和矩形
p = figure(plot_width=800, plot_height=400,toolbar_location="above",
tools = TOOLS)
# 添加toolbar p.circle(np.random.randn(500),np.random.randn(500))
show(p)

#联动
from bokeh.layouts import gridplot TOOLS = '''
box_select,lasso_select,
reset
'''
df = pd.DataFrame(np.random.randn(500,2), columns = ['A', 'B'])
source = ColumnDataSource(data=df) p1 = figure(plot_width=400, plot_height=400,toolbar_location="above",tools = TOOLS)
p2 = figure(plot_width=400, plot_height=400,toolbar_location="above",tools = TOOLS) p1.circle(x='index', y='A',source=source)
p2.line(x='index', y='B',source=source)
s = gridplot([[p1, p2]])
show(s)

4. 提示框、十字线

# 工具栏 tools
# (4)提示框、十字线 from bokeh.models import HoverTool
# 用于设置显示标签内容 df = pd.DataFrame({'A':np.random.randn(500)*100,
'B':np.random.randn(500)*100,
'type':np.random.choice(['pooh', 'rabbit', 'piglet', 'Christopher'],500),
'color':np.random.choice(['red', 'yellow', 'blue', 'green'],500)})
df.index.name = 'index'
source = ColumnDataSource(df)
print(df.head())
# 创建数据 → 包含四个标签 p1 = figure(plot_width=800, plot_height=400,toolbar_location="above",
tools=['hover,box_select,reset,wheel_zoom,pan,crosshair']) # 注意这里书写方式; hover它的作用是只是会显示出点的每个标签;crossshair是显示十字叉
# 如果不设置标签,就只写hover,例如 tools='hover,box_select,reset,wheel_zoom,pan,crosshair'
p1.circle(x = 'A',y = 'B',source = source,size = 10,alpha = 0.3, color = 'color')
show(p1)

from bokeh.models import HoverTool
# 用于设置显示标签内容 df = pd.DataFrame({'A':np.random.randn(500)*100,
'B':np.random.randn(500)*100,
'type':np.random.choice(['pooh', 'rabbit', 'piglet', 'Christopher'],500),
'color':np.random.choice(['red', 'yellow', 'blue', 'green'],500)})
df.index.name = 'index'
source = ColumnDataSource(df)
print(df.head())
# 创建数据 → 包含四个标签 hover = HoverTool(tooltips=[
("index", "$index"),
("(x,y)", "($x, $y)"),
("A", "@A"),
("B", "@B"),
("type", "@type"),
("color", "@color"),
])
# 设置标签显示内容
# $index:自动计算 → 数据index
# $x:自动计算 → 数据x值
# $y:自动计算 → 数据y值
# @A:显示ColumnDataSource中对应字段值 p1 = figure(plot_width=800, plot_height=400,toolbar_location="above",
tools=[hover,'box_select,reset,wheel_zoom,pan,crosshair']) # 注意这里书写方式; hover它的作用是只是会显示出点的每个标签;crossshair是显示十字叉
# 如果不设置标签,就只写hover,例如 tools='hover,box_select,reset,wheel_zoom,pan,crosshair'
p1.circle(x = 'A',y = 'B',source = source,size = 10,alpha = 0.3, color = 'color')
show(p1) p2 = figure(plot_width=800, plot_height=400,toolbar_location="above",
tools=[hover,'box_select,reset,wheel_zoom,pan'])
p2.vbar(x = 'index', width=1, top='A',source = source)
show(p2)
print(hover) #就是一个生成器

HoverTool(id='3b80258a-2940-4c8a-af3e-9a3905cb7c09', ...)

5. 筛选数据

隐藏

# 1、筛选数据 - 隐藏
# legend.click_policy from bokeh.palettes import Spectral4
# 导入颜色模块 df = pd.DataFrame({'A':np.random.randn(500).cumsum(),
'B':np.random.randn(500).cumsum(),
'C':np.random.randn(500).cumsum(),
'D':np.random.randn(500).cumsum()},
index = pd.date_range('',freq = 'D',periods=500))
# 创建数据 p = figure(plot_width=800, plot_height=400, x_axis_type="datetime")
p.title.text = '点击图例来隐藏数据' for col,color in zip(df.columns.tolist(),Spectral4):
p.line(df.index,df[col],line_width=2, color=color, alpha=0.8,legend = col) p.legend.location = "top_left"
p.legend.click_policy="hide"
# 设置图例,点击隐藏 show(p)

消隐

# 1、筛选数据 - 消隐
# legend.click_policy from bokeh.palettes import Spectral4
# 导入颜色模块 df = pd.DataFrame({'A':np.random.randn(500).cumsum(),
'B':np.random.randn(500).cumsum(),
'C':np.random.randn(500).cumsum(),
'D':np.random.randn(500).cumsum()},
index = pd.date_range('',freq = 'D',periods=500))
# 创建数据 p = figure(plot_width=800, plot_height=400, x_axis_type="datetime")
p.title.text = '点击图例来隐藏数据' for col,color in zip(df.columns.tolist(),Spectral4):
p.line(df.index,df[col],line_width=2, color=color, alpha=0.8,legend = col,
muted_color=color, muted_alpha=0.2) # 设置消隐后的显示颜色、透明度 可以设置muted_color = 'black' p.legend.location = "top_left"
p.legend.click_policy="mute"
# 设置图例,点击隐藏 show(p)

6. 交互工具

# 2、交互小工具
# 图表分页 from bokeh.models.widgets import Panel, Tabs
# 导入panel,tabs模块 p1 = figure(plot_width=500, plot_height=300)
p1.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
tab1 = Panel(child=p1, title="circle")
# child → 页码
# title → 分页名称 p2 = figure(plot_width=500, plot_height=300)
p2.line([1, 2, 3, 4, 5], [4, 2, 3, 8, 6], line_width=3, color="navy", alpha=0.5)
tab2 = Panel(child=p2, title="line") tabs = Tabs(tabs=[ tab1, tab2 ])
# 设置分页图表 show(tabs)

 

Python交互图表可视化Bokeh:7. 工具栏的更多相关文章

  1. Python交互图表可视化Bokeh:1. 可视交互化原理| 基本设置

    Bokeh pandas和matplotlib就可以直接出分析的图表了,最基本的出图方式.是面向数据分析过程中出图的工具:Seaborn相比matplotlib封装了一些对数据的组合和识别的功能:用S ...

  2. Python交互图表可视化Bokeh:5 柱状图| 堆叠图| 直方图

    柱状图/堆叠图/直方图 ① 单系列柱状图② 多系列柱状图③ 堆叠图④ 直方图 1.单系列柱状图 import numpy as np import pandas as pd import matplo ...

  3. Python交互图表可视化Bokeh:6. 轴线| 浮动| 多图表

    绘图表达进阶操作 ① 轴线设置② 浮动设置③ 多图表设置 1. 轴线标签设置 设置字符串 import numpy as np import pandas as pd import matplotli ...

  4. Python交互图表可视化Bokeh:4. 折线图| 面积图

    折线图与面积图 ① 单线图.多线图② 面积图.堆叠面积图 1. 折线图--单线图 import numpy as np import pandas as pd import matplotlib.py ...

  5. Python交互图表可视化Bokeh:3. 散点图

    散点图 ① 基本散点图绘制② 散点图颜色.大小设置方法③ 不同符号的散点图 1. 基本散点图绘制 import numpy as np import pandas as pd import matpl ...

  6. Python交互图表可视化Bokeh:2. 辅助参数

    图表辅助参数设置 辅助标注.注释.矢量箭头 参考官方文档:https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#col ...

  7. Python绘制六种可视化图表详解,三维图最炫酷!你觉得呢?

    Python绘制六种可视化图表详解,三维图最炫酷!你觉得呢? 可视化图表,有相当多种,但常见的也就下面几种,其他比较复杂一点,大都也是基于如下几种进行组合,变换出来的.对于初学者来说,很容易被这官网上 ...

  8. Python 数据图表工具的比较

    Python 的科学栈相当成熟,各种应用场景都有相关的模块,包括机器学习和数据分析.数据可视化是发现数据和展示结果的重要一环,只不过过去以来,相对于 R 这样的工具,发展还是落后一些. 幸运的是,过去 ...

  9. Python绘图与可视化

    Python有很多可视化工具,本篇只介绍Matplotlib. Matplotlib是一种2D的绘图库,它可以支持硬拷贝和跨系统的交互,它可以在Python脚本.IPython的交互环境下.Web应用 ...

随机推荐

  1. Laravel-Excel 导入 Excel 文件----为什么只获取到最后一行数据?

    ### 今天使用了Laravel-Excel 到类文件,想做一个excel  文件到导入和导出,但是看了 官方到文档示例,自己做了一下,发现 只取到到最后一行到数据, 有点摸不着头脑! 网上找了一下, ...

  2. 在Amazon FreeRTOS V10中使用运行时统计信息

    在MCU on Eclipse网站上看到Erich Styger在8月2日发的博文,一篇关于在Amazon FreeRTOS V10中使用运行时统计信息的文章,本人觉得很有启发,特将其翻译过来以备参考 ...

  3. Modbus库开发笔记之八:CRC循环冗余校验的研究与实现

    谈到Modbus通讯自然免不了循环冗余校验(CRC),特别是在标准的串行RTU链路上是必不可少的.不仅如此在其他开发中,也经常要用到CRC 算法对各种数据进行校验.这样一来,我们就需要研究一下这个循环 ...

  4. Oracle 数据库导入与出

    Oracle 数据库导入与出 导出( EXPORT )是用 EXP 将数据库部分或全对象的结构和导出 . 导入( 导入( IMPORT )是用 )是用 IMP IMP将 OS 文件中的对象结构和数据装 ...

  5. Confluence 6 发送 Confluence 通知到其他 Confluence 服务器

    你可以配置 Confluence 服务器向其他的 Confluence 服务器发送消息.在这种情况下,Confluence 服务器将不会显示 workbox. 希望发送消息到其他 Confluence ...

  6. js之DOM对象三

      一.JS中for循环遍历测试 for循环遍历有两种 第一种:是有条件的那种,例如    for(var i = 0;i<ele.length;i++){} 第二种:for (var i in ...

  7. CentOS 7 部署 Spring Boot

    Spring Boot 内嵌了tomcat .我们可以将Boot打成 jar 包丢到服务器上运行才行. Spring Boot已经帮我们打理好了这一切,如果项目是继承自 spring-boot-sta ...

  8. 对一个元素 同时添加单击onclick 和 双击ondblclick 触发冲突的解决

    需求说明:单击列表项内容后,吧啦吧啦,双击列表项内容后,巴拉巴拉巴拉~~~ 解决思路:卧槽 ,其实我是没思路的,当时唯一的想法就是,看个人点击鼠标的速度了,双击快一点,触发双击事件ლ(′◉❥◉`ლ), ...

  9. Python全栈习题一

    1.执行 Python 脚本的两种方式 a../run.py  直接在命令行调用python脚本: b.python run.py 调用python解释器来调用Python脚本. 2.简述位.字节的关 ...

  10. Linux 系统根目录下各个文件夹的作用

    原文: https://blog.csdn.net/qq_26941173/article/details/78376760 /bin 系统由很多放置可执行文件的目录,但是bin目录比较特殊.因为bi ...