python bokeh slider_Bokeh数据可视化工具3视觉增强及服务器
视觉增强
注释用于向绘图添加补充信息,例如标题,图例和彩色地图等。
Widget通过按钮,下拉菜单,滑块和提供交互性支持。
视觉属性为绘图提供了广泛的视觉增强,例如线条和文字的颜色和填充,以及诸如的交互增强
将鼠标悬停在工具上并选择兴趣点。
添加标题(title)#Setting up the data for chapter #Import the required packagesimport pandas as pdfrom bokeh.sampledata.stocks import AAPL
df_apple = pd.DataFrame(AAPL)
df_apple['date'] = pd.to_datetime(df_apple['date'])#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.plotting import figurefrom bokeh.plotting import ColumnDataSource#Create the ColumnDataSource objectdata = ColumnDataSource(data = { 'x' : df_apple['high'], 'y' : df_apple['low'], 'x1': df_apple['open'], 'y1': df_apple['close'], 'x2': df_apple['date'], 'y2': df_apple['volume'],
})#Adding titles to plots#Import the required packagesfrom bokeh.plotting import figure, show, output_file#Create the plot with the titleplot3 = figure(title = "5 year time series distribution of volumn of Apple stocks traded", title_location = "above",
x_axis_type = 'datetime', x_axis_label = 'date', y_axis_label = 'Volume Traded')#Create the time series plotplot3.line(x = 'x2', y = 'y2', source = data, color = 'red')
plot3.circle(x = 'x2', y = 'y2', source = data, fill_color = 'white', size = 3)#Output the plotoutput_file('title.html')
show(plot3)
image.png
添加图例(legend)#Setting up the data for chapter #Import the required packagesimport pandas as pdfrom bokeh.sampledata.stocks import AAPL
df_apple = pd.DataFrame(AAPL)
df_apple['date'] = pd.to_datetime(df_apple['date'])#Import the required packagesfrom bokeh.io import output_file, showfrom bokeh.plotting import figurefrom bokeh.plotting import ColumnDataSource#Create the ColumnDataSource objectdata = ColumnDataSource(data = { 'x' : df_apple['high'], 'y' : df_apple['low'], 'x1': df_apple['open'], 'y1': df_apple['close'], 'x2': df_apple['date'], 'y2': df_apple['volume'],
})#Adding legends to plots#Import the required packagesfrom bokeh.plotting import figure, show, output_file#Create the two scatter plotsplot = figure()#Create the legendsplot.cross(x = 'x', y = 'y', source = data, color = 'red', size = 10, alpha = 0.8, legend = "High Vs. Low")
plot.circle(x = 'x1', y = 'y1', source = data, color = 'green', size = 10, alpha = 0.3, legend = "Open Vs. Close")#Output the plotoutput_file('5.html')
show(plot)
image.png
颜色映射#Setting up the data for chapter import pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Import the required packagesfrom bokeh.models import CategoricalColorMapperfrom bokeh.io import output_file, showfrom bokeh.plotting import figurefrom bokeh.plotting import ColumnDataSource#Store the data in the ColumnDataSource objectdata = ColumnDataSource(df_multiple)#Create the mapper category_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])#Plot the figureplot = figure()
plot.circle('high', 'low', size = 8, source = data, color = {'field': 'Name', 'transform': category_map})#Output the plotoutput_file('category.html')
show(plot)
image.png
创建按钮(button)from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import Button#Create the buttonbutton = Button(label="Click me", button_type = "success")#Output the buttonoutput_file("button.html")
show(widgetbox(button))
image.png
复选框(checkbox)from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import CheckboxGroup#Create the checkboxcheckbox = CheckboxGroup(
labels=["box: 1", "box: 2", "box: 3"], active=[1, 2])#Output the checkboxoutput_file("checkbox.html")
show(widgetbox(checkbox))
image.png
下拉菜单(Dropdown)from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import Dropdown#Create the menumenu = [("Option 1", "item_1"), ("Option 2", "item_2")]#Create the Dropdowndropdown = Dropdown(label="Dropdown Menu", button_type="warning", menu=menu)#Output the dropdown menuoutput_file("dropdown.html")
show(widgetbox(dropdown))
image.png
单选按钮(radio)from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import RadioGroup#Create the radio button radio_button = RadioGroup(
labels=["Option 1", "Option 2"], active=0)#Output the radio button widgetoutput_file("radiobutton.html")
show(widgetbox(radio_button))
image.png
滑动条(slider)from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import Slider#Create the slider widgetslider = Slider(start=0, end=50, value=0, step= 5, title="Simple Slider")#Output the slideroutput_file("slider.html")
show(widgetbox(slider))
image.png
文本输入from bokeh.io import output_file, showfrom bokeh.layouts import widgetboxfrom bokeh.models.widgets import TextInput#Create the text input widgettext_widget = TextInput(value="", title="Type your text here")#Output the text input widgetoutput_file("text_input.html")
show(widgetbox(text_widget))
image.png
悬停提示from bokeh.models import CategoricalColorMapperfrom bokeh.models import HoverToolfrom bokeh.io import output_file, showfrom bokeh.plotting import ColumnDataSourcefrom bokeh.plotting import figureimport pandas as pd#Read in the data and filter for Google and USB stocksimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Create the hover tooltiphover_tool = HoverTool(tooltips = [
('Stock Ticker', '@Name'),
('High Price', '@high'),
('Low Price', '@low')
])
#Save the data in a ColumnDataSource objectdata = ColumnDataSource(df_multiple)#Create the categorical color mappercategory_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])#Create the plot with the hover tooltipplot = figure(tools = [hover_tool])
plot.circle('high', 'low', size = 8, source = data, color = {'field': 'Name', 'transform': category_map})#Output the plotoutput_file('hover.html')
show(plot)
image.png
选择from bokeh.models import CategoricalColorMapperfrom bokeh.models import HoverToolfrom bokeh.io import output_file, showfrom bokeh.plotting import ColumnDataSourcefrom bokeh.plotting import figureimport pandas as pd#Read in the data and filter for Google and USB stocksimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Save the data in a ColumnDataSource objectdata = ColumnDataSource(df_multiple)
category_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])#Create the plot with the selection tool plot = figure(tools = 'box_select')
plot.circle('high', 'low', size = 8, source = data,
color = {'field': 'Name', 'transform': category_map}, selection_color = 'green',
nonselection_fill_alpha = 0.3, nonselection_fill_color = 'grey')#Output the plotoutput_file('selection.html')
show(plot)
image.png
标题样式from bokeh.models import CategoricalColorMapperfrom bokeh.models import HoverToolfrom bokeh.io import output_file, showfrom bokeh.plotting import ColumnDataSourcefrom bokeh.plotting import figureimport pandas as pd#Read in the data and filter for Google and USB stocksimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Save the data in a ColumnDataSource objectdata = ColumnDataSource(df_multiple)
category_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])
plot = figure(title = "High Vs. Low Prices (Google & USB)")
plot.title.text_color = "red"plot.title.text_font = "times"plot.title.text_font_style = "bold"plot.circle('high', 'low', size = 8, source = data,
color = {'field': 'Name', 'transform': category_map})#Output the plotoutput_file('title.html')
show(plot)
image.png
轮廓样式from bokeh.models import CategoricalColorMapperfrom bokeh.models import HoverToolfrom bokeh.io import output_file, showfrom bokeh.plotting import ColumnDataSourcefrom bokeh.plotting import figureimport pandas as pd#Read in the data and filter for Google and USB stocksimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Save the data in a ColumnDataSource objectdata = ColumnDataSource(df_multiple)
category_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])
plot = figure(title = "High Vs. Low Prices (Google & USB)")#Configure the outline of the plotplot.outline_line_width = 8plot.outline_line_alpha = 0.8plot.outline_line_color = "black"#Create and output the plotplot.circle('high', 'low', size = 8, source = data,
color = {'field': 'Name', 'transform': category_map})
output_file('outline.html')
show(plot)
image.png
标签样式from bokeh.models import CategoricalColorMapperfrom bokeh.models import HoverToolfrom bokeh.io import output_file, showfrom bokeh.plotting import ColumnDataSourcefrom bokeh.plotting import figureimport pandas as pd#Read in the data and filter for Google and USB stocksimport pandas as pd#Read in the datadf = pd.read_csv('/home/andrew/code/kaggle-code/stock_data/all_stocks_5yr.csv')
df_multiple = df[(df['Name'] == 'GOOGL') | (df['Name'] == 'USB')]#Save the data in a ColumnDataSource objectdata = ColumnDataSource(df_multiple)
category_map = CategoricalColorMapper(
factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])
plot = figure(title = "High Vs. Low Prices (Google & USB)")
plot.xaxis.axis_label = "High Prices"plot.xaxis.axis_label_text_color = "green"plot.yaxis.axis_label = "Low Prices"plot.yaxis.axis_label_text_font_style = "bold"plot.circle('high', 'low', size = 8, source = data,
color = {'field': 'Name', 'transform': category_map})#Output the plotoutput_file('label.html')
show(plot)
image.png
服务器
image.png
image.pngfrom bokeh.layouts import widgetboxfrom bokeh.models import Sliderfrom bokeh.io import curdoc#Create a slider widgetslider_widget = Slider(start = 0, end = 100, step = 10, title = 'Single Slider')#Create a layout for the widgetslider_layout = widgetbox(slider_widget)#Add the slider widget to the applicationcurdoc().add_root(slider_layout)$ bokeh serve --show 6_single_slider.py
2018-08-07 22:31:08,152 Starting Bokeh server version 0.13.0 (running on Tornado 5.0.2)2018-08-07 22:31:08,157 Bokeh app running at: http://localhost:5006/6_single_slider2018-08-07 22:31:08,157 Starting Bokeh server with process id: 4004[4014:4042:0807/223108.727386:ERROR:browser_gpu_channel_host_factory.cc(120)] Failed to launch GPU process.2018-08-07 22:31:08,734 200 GET /6_single_slider (::1) 25.01ms2018-08-07 22:31:09,235 101 GET /6_single_slider/ws?bokeh-protocol-version=1.0&bokeh-session-id=DIPJXgIOQBG65IwoBU8WsZ2dCevD8Ex0mrEfG9hKs1Gm (::1) 1.09ms2018-08-07 22:31:09,236 WebSocket connection opened2018-08-07 22:31:09,236 ServerConnection created
image.pngfrom bokeh.layouts import widgetboxfrom bokeh.models import Sliderfrom bokeh.io import curdoc#Create multiple slider widgetsslider_widget1 = Slider(start = 0, end = 100, step = 10, title = 'Slider 1')
slider_widget2 = Slider(start = 0, end = 50, step = 5, title = 'Slider 2')
slider_widget3 = Slider(start = 50, end = 100, step = 5, title = 'Slider 3')#Create a layout for the widgetslider_layout = widgetbox(slider_widget1, slider_widget2, slider_widget3)#Add the slider widget to the applicationcurdoc().add_root(slider_layout)
image.pngfrom bokeh.models import Slider, ColumnDataSourcefrom bokeh.io import curdocfrom bokeh.layouts import rowfrom bokeh.plotting import figurefrom numpy.random import random#Create data for the plotinitial_points = 500data_points = ColumnDataSource(data = {'x': random(initial_points), 'y': random(initial_points)})#Create the plotplot = figure(title = "Random scatter plot generator")
plot.diamond(x = 'x', y = 'y', source = data_points, color = 'red')#Create the slider widgetslider_widget = Slider(start = 0, end = 10000, step = 10, value = initial_points, title = 'Slide right to increase number of points')#Define the callback functiondef callback(attr, old, new):
points = slider_widget.value
data_points.data = {'x': random(points), 'y': random(points)}
slider_widget.on_change('value', callback)#Create a layout for the applicationlayout = row(slider_widget, plot)#Add the layout to the applicationcurdoc().add_root(layout)
作者:python作业AI毕业设计
链接:https://www.jianshu.com/p/1e657b9afd3b
python bokeh slider_Bokeh数据可视化工具3视觉增强及服务器相关推荐
- Python中的数据可视化工具与方法——常用的数据分析包numpy、pandas、statistics的理解实现和可视化工具matplotlib的使用
Python中的数据可视化工具与方法 本文主要总结了: 1.本人在初学python时对常用的数据分析包numpy.pandas.statistics的学习理解以及简单的实例实现 2.可视化工具matp ...
- python bokeh 3d_Python数据可视化:基于Bokeh的可视化绘图
前言 第1章 准备工作 1.1 安装Anaconda 1.2 运行Jupyter Notebook 1.3 基本概念 第2章 绘制基本图形 2.1 绘图方法 2.2 散点图 2.3 气泡图 2.4 折 ...
- python交互式数据可视化_python数据可视化工具
熟知python的人都知道,python上常用的一款数据可视化工具是Matplotlib,但是Matplotlib是静态的.那么,Python中除了matplotlib外,还有哪些数据可视化工具呢?其 ...
- python在线工具-6 种 Python 数据可视化工具
原标题:6 种 Python 数据可视化工具 英文:Chris Moffitt,编译:伯乐在线/李加庆 简介 在 Python 中,将数据可视化有多种选择,正是因为这种多样性,何时选用何种方案才变得极 ...
- python可视化图表工具_酷炫的可视化图表工具来帮忙 深度评测五大Python数据可视化工具...
原标题:酷炫的可视化图表工具来帮忙 深度评测五大Python数据可视化工具 不少Python用户的一大诉求是做出各种酷炫的可视化图表,而这就需要了解清楚工具特色,才好在制作不同类型图表顺利找到适合自己 ...
- python基于web可视化_独家 | 基于Python实现交互式数据可视化的工具(用于Web)
转自:数据派ID:datapi 作者:Alark Joshi 翻译:陈雨琳 校对:吴金笛 本文2200字,建议阅读8分钟. 本文将介绍实现数据可视化的软件包. 这学期(2018学年春季学期)我教授了一 ...
- python数据可视化的特点_6 种 Python 数据可视化工具
原标题:6 种 Python 数据可视化工具 英文:Chris Moffitt,编译:伯乐在线/李加庆 简介 在 Python 中,将数据可视化有多种选择,正是因为这种多样性,何时选用何种方案才变得极 ...
- python交互式数据可视化_基于Python实现交互式数据可视化的工具,你用过几种?...
作者:Alark Joshi 翻译:陈雨琳 来源:数据派THU(ID:DatapiTHU) 我教授了一门关于数据可视化的数据科学硕士课程.我们的数据科学硕士项目是一个为期15个月的强化项目,这个项目已 ...
- python实现数据可视化软件_基于Python实现交互式数据可视化的工具
作者:Alark Joshi 翻译:陈雨琳 校对:吴金笛 本文2200字,建议阅读8分钟. 本文将介绍实现数据可视化的软件包. 这学期(2018学年春季学期)我教授了一门关于数据可视化的数据科学硕士课 ...
最新文章
- Handler消息机制(十):HandlerThread源码解析
- tab-pane 怎么家点击事件_有好转?辛巴燕窝事件新进展曝光。二子爷老婆首次回应银行行长送奥迪!二子爷分析小样你家老铁太精...
- springboot中java泛型使用
- myisam怎么读_耗时半年,我成功“逆袭”,拿下美团offer(刷面试题+读源码+项目准备)...
- python语言及其应用电子版翁正秋_Python语言及其应用pdf
- 论__AlertDialog自定义布局回调修改的正确方式
- 一起谈.NET技术,编写T4模板无法避免的两个话题:quot;Assembly Lockingquot;amp;quot;Debugquot;...
- ArrayList 的三种构造方法
- 国际结算习题集及答案
- word转pdf或者打印后题注编号变成大写
- 开发者需要什么样的技术社区?
- Keil4与keil5共存问题
- matlab计算梁截面特性,MATLAB环境下叶片截面几何特性计算程序的设计
- Mac 自带 输入法 无法打出 一些汉字 生僻字 的问题,解决办法。
- Android 11 WiFi热点打开与关闭接口
- 计算机公共课4-电子表格系统 Excel 2010
- Odoo16 主题推荐
- 一个iOS程序员的BAT面试经验
- for...in 与 for...of 的用法与区别
- 百度地图 -- 鼠标绘制工具DrawingManager
热门文章
- 如何在 Linux 中使用 AppImage
- 双十一喜报式实时成交额今年没了
- YVU420PackedSemiPlanar32m4ka与YUV420PackedSemiPlanar64x32Tile2m8ka
- 内存-ECC RDIMM 服务器内存条简介(常被叫做RECC内存条)
- 九江职业学院计算机专业怎么样,请问九江职业大学和九江职业技术学院,相比之下哪个好一点?...
- python k线顶分型_顶分型底分型代码
- onedrive不同版本
- centos8 yum安装mysql8 流程配置
- nginx清缓存,网站刷新不过来时用
- mysql navicat 多语句_使用Navicat多对多关系SQL语句在MySQL中实现