神刀安全网

[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

注释用于向绘图添加补充信息,例如标题,图例和彩色地图等。
Widget通过按钮,下拉菜单,滑块和提供交互性支持。
视觉属性为绘图提供了广泛的视觉增强,例如线条和文字的颜色和填充,以及诸如的交互增强
将鼠标悬停在工具上并选择兴趣点。

添加标题(title)

#Setting up the data for chapter  #Import the required packages import pandas as pd from bokeh.sampledata.stocks import AAPL  df_apple = pd.DataFrame(AAPL) df_apple['date'] = pd.to_datetime(df_apple['date'])  #Import the required packages from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.plotting import ColumnDataSource  #Create the ColumnDataSource object data = 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 packages from bokeh.plotting import figure, show, output_file  #Create the plot with the title plot3 = 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 plot plot3.line(x = 'x2', y = 'y2', source = data, color = 'red') plot3.circle(x = 'x2', y = 'y2', source = data, fill_color = 'white', size = 3)  #Output the plot output_file('title.html') show(plot3) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

添加图例(legend)

#Setting up the data for chapter  #Import the required packages import pandas as pd from bokeh.sampledata.stocks import AAPL  df_apple = pd.DataFrame(AAPL) df_apple['date'] = pd.to_datetime(df_apple['date'])  #Import the required packages from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.plotting import ColumnDataSource  #Create the ColumnDataSource object data = 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 packages from bokeh.plotting import figure, show, output_file  #Create the two scatter plots plot = figure()  #Create the legends plot.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 plot output_file('5.html') show(plot) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

颜色映射

#Setting up the data for chapter  import pandas as pd  #Read in the data df = 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 packages from bokeh.models import CategoricalColorMapper from bokeh.io import output_file, show from bokeh.plotting import figure from bokeh.plotting import ColumnDataSource  #Store the data in the ColumnDataSource object data = ColumnDataSource(df_multiple)  #Create the mapper  category_map = CategoricalColorMapper(     factors = ['GOOGL', 'USB'], palette = ['blue', 'red'])  #Plot the figure plot = figure() plot.circle('high', 'low', size = 8, source = data, color = {'field': 'Name', 'transform': category_map})  #Output the plot output_file('category.html') show(plot) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

创建按钮(button)

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import Button  #Create the button button = Button(label="Click me", button_type = "success")  #Output the button output_file("button.html") show(widgetbox(button)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

复选框(checkbox)

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import CheckboxGroup  #Create the checkbox checkbox = CheckboxGroup(         labels=["box: 1", "box: 2", "box: 3"], active=[1, 2])  #Output the checkbox output_file("checkbox.html") show(widgetbox(checkbox)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

下拉菜单(Dropdown)

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import Dropdown  #Create the menu menu = [("Option 1", "item_1"), ("Option 2", "item_2")]  #Create the Dropdown dropdown = Dropdown(label="Dropdown Menu", button_type="warning", menu=menu)  #Output the dropdown menu output_file("dropdown.html") show(widgetbox(dropdown)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

单选按钮(radio)

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import RadioGroup  #Create the radio button  radio_button = RadioGroup(         labels=["Option 1", "Option 2"], active=0)  #Output the radio button widget output_file("radiobutton.html") show(widgetbox(radio_button)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

滑动条(slider)

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import Slider  #Create the slider widget slider = Slider(start=0, end=50, value=0, step= 5, title="Simple Slider")  #Output the slider output_file("slider.html") show(widgetbox(slider)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

文本输入

from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import TextInput  #Create the text input widget text_widget = TextInput(value="", title="Type your text here")  #Output the text input widget output_file("text_input.html") show(widgetbox(text_widget)) 
[雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

image.png

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » [雪峰磁针石博客]Bokeh数据可视化工具5视觉增强

分享到:更多 ()