SlideShare a Scribd company logo
PythonForDataScience Cheat Sheet
Bokeh
Learn Bokeh Interactively at www.DataCamp.com,
taught by Bryan Van de Ven, core contributor
Plotting With Bokeh
DataCamp
Learn Python for Data Science Interactively
>>> from bokeh.plotting import figure
>>> p1 = figure(plot_width=300, tools='pan,box_zoom')
>>> p2 = figure(plot_width=300, plot_height=300,
x_range=(0, 8), y_range=(0, 8))
>>> p3 = figure()
>>> from bokeh.io import output_notebook, show
>>> output_notebook()
Plotting
Standalone HTML
>>> from bokeh.embed import file_html
>>> html = file_html(p, CDN, "my_plot")
Components
>>> from bokeh.embed import components
>>> script, div = components(p)
Rows & Columns Layout
Rows
>>> from bokeh.layouts import row
>>> layout = row(p1,p2,p3)
Grid Layout
>>> from bokeh.layouts import gridplot
>>> row1 = [p1,p2]
>>> row2 = [p3]
>>> layout = gridplot([[p1,p2],[p3]])
Tabbed Layout
>>> from bokeh.models.widgets import Panel, Tabs
>>> tab1 = Panel(child=p1, title="tab1")
>>> tab2 = Panel(child=p2, title="tab2")
>>> layout = Tabs(tabs=[tab1, tab2])
Selection and Non-Selection Glyphs
>>> p = figure(tools='box_select')
>>> p.circle('mpg', 'cyl', source=cds_df,
selection_color='red',
nonselection_alpha=0.1)
Hover Glyphs
>>> hover = HoverTool(tooltips=None, mode='vline')
>>> p3.add_tools(hover)
Colormapping
>>> color_mapper = CategoricalColorMapper(
factors=['US', 'Asia', 'Europe'],
palette=['blue', 'red', 'green'])
>>> p3.circle('mpg', 'cyl', source=cds_df,
color=dict(field='origin',
transform=color_mapper),
legend='Origin'))
Linked Plots
>>> from bokeh.io import output_file, show
>>> output_file('my_bar_chart.html', mode='cdn')
>>> from bokeh.models import ColumnDataSource
>>> cds_df = ColumnDataSource(df)
Data Also see Lists, NumPy & Pandas
Under the hood, your data is converted to Column Data
Sources. You can also do this manually:
Customized Glyphs
Inside Plot Area
>>> p.legend.location = 'bottom_left'
Outside Plot Area
>>> r1 = p2.asterisk(np.array([1,2,3]), np.array([3,2,1])
>>> r2 = p2.line([1,2,3,4], [3,4,5,6])
>>> legend = Legend(items=[("One" , [p1, r1]),("Two" , [r2])], location=(0, -30))
>>> p.add_layout(legend, 'right')
The Python interactive visualization library Bokeh
enables high-performance visual presentation of
large datasets in modern web browsers.
Bokeh’s mid-level general purpose bokeh.plotting
interface is centered around two main components: data
and glyphs.
The basic steps to creating plots with the bokeh.plotting
interface are:
1. Prepare some data:
Python lists, NumPy arrays, Pandas DataFrames and other sequences of values
2. Create a new plot
3. Add renderers for your data, with visual customizations
4. Specify where to generate the output
5. Show or save the results
+ =
data glyphs plot
>>> from bokeh.plotting import figure
>>> from bokeh.io import output_file, show
>>> x = [1, 2, 3, 4, 5]
>>> y = [6, 7, 2, 4, 5]
>>> p = figure(title="simple line example",
x_axis_label='x',
y_axis_label='y')
>>> p.line(x, y, legend="Temp.", line_width=2)
>>> output_file("lines.html")
>>> show(p)
Step 4
Step 2
Step 1
Step 5
Step 3
Renderers & Visual Customizations
>>> p.legend.orientation = "horizontal"
>>> p.legend.orientation = "vertical"
>>> from bokeh.charts import Bar
>>> p = Bar(df, stacked=True, palette=['red','blue'])
Bar Chart
Box Plot
Histogram
Scatter Plot
>>> from bokeh.charts import BoxPlot
>>> p = BoxPlot(df, values='vals', label='cyl',
legend='bottom_right')
>>> from bokeh.charts import Histogram
>>> p = Histogram(df, title='Histogram')
>>> from bokeh.charts import Scatter
>>> p = Scatter(df, x='mpg', y ='hp', marker='square',
xlabel='Miles Per Gallon',
ylabel='Horsepower')
>>> show(p1) >>> save(p1)
>>> show(layout) >>> save(layout)
Label 1
Label 2
Label 3
Histogram
x-axis
y-axis
2
Scatter Markers
>>> p1.circle(np.array([1,2,3]), np.array([3,2,1]),
fill_color='white')
>>> p2.square(np.array([1.5,3.5,5.5]), [1,4,3],
color='blue', size=1)
Line Glyphs
>>> p1.line([1,2,3,4], [3,4,5,6], line_width=2)
>>> p2.multi_line(pd.DataFrame([[1,2,3],[5,6,7]]),
pd.DataFrame([[3,4,5],[3,2,1]]),
color="blue")
3
Glyphs
Output4
Output to HTML File
Notebook Output
Show or Save Your Plots5
1
Legends
Columns
>>> from bokeh.layouts import columns
>>> layout = column(p1,p2,p3)
Linked Axes
>>> p2.x_range = p1.x_range
>>> p2.y_range = p1.y_range
Linked Brushing
>>> p4 = figure(plot_width = 100, tools='box_select,lasso_select')
>>> p4.circle('mpg', 'cyl', source=cds_df)
>>> p5 = figure(plot_width = 200, tools='box_select,lasso_select')
>>> p5.circle('mpg', 'hp', source=cds_df)
>>> layout = row(p4,p5)
Nesting Rows & Columns
>>>layout = row(column(p1,p2), p3)
Legend Location Legend Orientation
Legend Background & Border
>>> p.legend.border_line_color = "navy"
>>> p.legend.background_fill_color = "white"
>>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame(np.array([[33.9,4,65, 'US'],
[32.4,4,66, 'Asia'],
[21.4,4,109, 'Europe']]),
columns=['mpg','cyl', 'hp', 'origin'],
index=['Toyota', 'Fiat', 'Volvo'])
Also see Data
Also see Data
Embedding
Statistical Charts With Bokeh
Bokeh’s high-level bokeh.charts interface is ideal for quickly
creating statistical charts
Also see Data
US
Asia
Europe

More Related Content

What's hot

Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
Gil Cohen
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
Namgee Lee
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
Lukasz Dobrzanski
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Nishant Upadhyay
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3
sxw2k
 
Pytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedPytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math Impaired
Tyrel Denison
 
Deep learning study 3
Deep learning study 3Deep learning study 3
Deep learning study 3
San Kim
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
Svet Ivantchev
 
1 pythonbasic
1 pythonbasic1 pythonbasic
1 pythonbasic
pramod naik
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Welcome to python
Welcome to pythonWelcome to python
Welcome to python
Kyunghoon Kim
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Enthought, Inc.
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
Faraz Ahmed
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
Yoshiki Satotani
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
Roberto Pepato
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
GlowTouch
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
The Statistical and Applied Mathematical Sciences Institute
 

What's hot (19)

Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3
 
Pytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math ImpairedPytorch and Machine Learning for the Math Impaired
Pytorch and Machine Learning for the Math Impaired
 
Deep learning study 3
Deep learning study 3Deep learning study 3
Deep learning study 3
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
1 pythonbasic
1 pythonbasic1 pythonbasic
1 pythonbasic
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Welcome to python
Welcome to pythonWelcome to python
Welcome to python
 
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with MayaviScientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
Scientific Computing with Python Webinar March 19: 3D Visualization with Mayavi
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
 
Haskell 101
Haskell 101Haskell 101
Haskell 101
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
 

Similar to Python bokeh cheat_sheet

Chapter04.pptx
Chapter04.pptxChapter04.pptx
Chapter04.pptx
GiannisPagges
 
Objects and Graphics
Objects and GraphicsObjects and Graphics
Objects and Graphics
Edwin Flórez Gómez
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
RamziFeghali
 
Pymongo for the Clueless
Pymongo for the CluelessPymongo for the Clueless
Pymongo for the Clueless
Chee Leong Chow
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
Colin Su
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rick Copeland
 
Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in Angular
Yadong Xie
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
Mahmoud Samir Fayed
 
python modules1522.pdf
python modules1522.pdfpython modules1522.pdf
python modules1522.pdf
DebanjanMaity13
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화
Tae wook kang
 
Mock Hell PyCon DE and PyData Berlin 2019
Mock Hell PyCon DE and PyData Berlin 2019Mock Hell PyCon DE and PyData Berlin 2019
Mock Hell PyCon DE and PyData Berlin 2019
Edwin Jung
 
shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
Ashwini Kalantri
 
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
Produce nice outputs for graphical, tabular and textual reporting in R-Report...Produce nice outputs for graphical, tabular and textual reporting in R-Report...
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
Dr. Volkan OBAN
 
The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202
Mahmoud Samir Fayed
 
Introduction to AspectJ
Introduction to AspectJIntroduction to AspectJ
Introduction to AspectJ
mukhtarhudaya
 
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxbbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
ikirkton
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리
용 최
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appcelerator
Alessio Ricco
 
The MongoDB Driver for F#
The MongoDB Driver for F#The MongoDB Driver for F#
The MongoDB Driver for F#
MongoDB
 

Similar to Python bokeh cheat_sheet (20)

Chapter04.pptx
Chapter04.pptxChapter04.pptx
Chapter04.pptx
 
Objects and Graphics
Objects and GraphicsObjects and Graphics
Objects and Graphics
 
Pres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdfPres_python_talakhoury_26_09_2023.pdf
Pres_python_talakhoury_26_09_2023.pdf
 
Pymongo for the Clueless
Pymongo for the CluelessPymongo for the Clueless
Pymongo for the Clueless
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and MingRapid and Scalable Development with MongoDB, PyMongo, and Ming
Rapid and Scalable Development with MongoDB, PyMongo, and Ming
 
Hidden Docs in Angular
Hidden Docs in AngularHidden Docs in Angular
Hidden Docs in Angular
 
The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181The Ring programming language version 1.5.2 book - Part 44 of 181
The Ring programming language version 1.5.2 book - Part 44 of 181
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
python modules1522.pdf
python modules1522.pdfpython modules1522.pdf
python modules1522.pdf
 
Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화Python과 node.js기반 데이터 분석 및 가시화
Python과 node.js기반 데이터 분석 및 가시화
 
Mock Hell PyCon DE and PyData Berlin 2019
Mock Hell PyCon DE and PyData Berlin 2019Mock Hell PyCon DE and PyData Berlin 2019
Mock Hell PyCon DE and PyData Berlin 2019
 
shiny.pdf
shiny.pdfshiny.pdf
shiny.pdf
 
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
Produce nice outputs for graphical, tabular and textual reporting in R-Report...Produce nice outputs for graphical, tabular and textual reporting in R-Report...
Produce nice outputs for graphical, tabular and textual reporting in R-Report...
 
The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202
 
Introduction to AspectJ
Introduction to AspectJIntroduction to AspectJ
Introduction to AspectJ
 
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docxbbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
bbyopenApp_Code.DS_StorebbyopenApp_CodeVBCodeGoogleMaps.docx
 
Python 표준 라이브러리
Python 표준 라이브러리Python 표준 라이브러리
Python 표준 라이브러리
 
Writing videogames with titanium appcelerator
Writing videogames with titanium appceleratorWriting videogames with titanium appcelerator
Writing videogames with titanium appcelerator
 
The MongoDB Driver for F#
The MongoDB Driver for F#The MongoDB Driver for F#
The MongoDB Driver for F#
 

More from Nishant Upadhyay

Multivariate calculus
Multivariate calculusMultivariate calculus
Multivariate calculus
Nishant Upadhyay
 
Multivariate calculus
Multivariate calculusMultivariate calculus
Multivariate calculus
Nishant Upadhyay
 
Matrices1
Matrices1Matrices1
Matrices1
Nishant Upadhyay
 
Vectors2
Vectors2Vectors2
Mathematics for machine learning calculus formulasheet
Mathematics for machine learning calculus formulasheetMathematics for machine learning calculus formulasheet
Mathematics for machine learning calculus formulasheet
Nishant Upadhyay
 
Maths4ml linearalgebra-formula
Maths4ml linearalgebra-formulaMaths4ml linearalgebra-formula
Maths4ml linearalgebra-formula
Nishant Upadhyay
 
Sqlcheetsheet
SqlcheetsheetSqlcheetsheet
Sqlcheetsheet
Nishant Upadhyay
 
Sql cheat-sheet
Sql cheat-sheetSql cheat-sheet
Sql cheat-sheet
Nishant Upadhyay
 
My sql installationguide_windows
My sql installationguide_windowsMy sql installationguide_windows
My sql installationguide_windows
Nishant Upadhyay
 
Company handout
Company handoutCompany handout
Company handout
Nishant Upadhyay
 
Foliumcheatsheet
FoliumcheatsheetFoliumcheatsheet
Foliumcheatsheet
Nishant Upadhyay
 

More from Nishant Upadhyay (11)

Multivariate calculus
Multivariate calculusMultivariate calculus
Multivariate calculus
 
Multivariate calculus
Multivariate calculusMultivariate calculus
Multivariate calculus
 
Matrices1
Matrices1Matrices1
Matrices1
 
Vectors2
Vectors2Vectors2
Vectors2
 
Mathematics for machine learning calculus formulasheet
Mathematics for machine learning calculus formulasheetMathematics for machine learning calculus formulasheet
Mathematics for machine learning calculus formulasheet
 
Maths4ml linearalgebra-formula
Maths4ml linearalgebra-formulaMaths4ml linearalgebra-formula
Maths4ml linearalgebra-formula
 
Sqlcheetsheet
SqlcheetsheetSqlcheetsheet
Sqlcheetsheet
 
Sql cheat-sheet
Sql cheat-sheetSql cheat-sheet
Sql cheat-sheet
 
My sql installationguide_windows
My sql installationguide_windowsMy sql installationguide_windows
My sql installationguide_windows
 
Company handout
Company handoutCompany handout
Company handout
 
Foliumcheatsheet
FoliumcheatsheetFoliumcheatsheet
Foliumcheatsheet
 

Recently uploaded

一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
rwarrenll
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
mzpolocfi
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
dwreak4tg
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
74nqk8xf
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
zsjl4mimo
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 

Recently uploaded (20)

一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.My burning issue is homelessness K.C.M.O.
My burning issue is homelessness K.C.M.O.
 
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
一比一原版(Dalhousie毕业证书)达尔豪斯大学毕业证如何办理
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
一比一原版(Chester毕业证书)切斯特大学毕业证如何办理
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
一比一原版(Harvard毕业证书)哈佛大学毕业证如何办理
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 

Python bokeh cheat_sheet

  • 1. PythonForDataScience Cheat Sheet Bokeh Learn Bokeh Interactively at www.DataCamp.com, taught by Bryan Van de Ven, core contributor Plotting With Bokeh DataCamp Learn Python for Data Science Interactively >>> from bokeh.plotting import figure >>> p1 = figure(plot_width=300, tools='pan,box_zoom') >>> p2 = figure(plot_width=300, plot_height=300, x_range=(0, 8), y_range=(0, 8)) >>> p3 = figure() >>> from bokeh.io import output_notebook, show >>> output_notebook() Plotting Standalone HTML >>> from bokeh.embed import file_html >>> html = file_html(p, CDN, "my_plot") Components >>> from bokeh.embed import components >>> script, div = components(p) Rows & Columns Layout Rows >>> from bokeh.layouts import row >>> layout = row(p1,p2,p3) Grid Layout >>> from bokeh.layouts import gridplot >>> row1 = [p1,p2] >>> row2 = [p3] >>> layout = gridplot([[p1,p2],[p3]]) Tabbed Layout >>> from bokeh.models.widgets import Panel, Tabs >>> tab1 = Panel(child=p1, title="tab1") >>> tab2 = Panel(child=p2, title="tab2") >>> layout = Tabs(tabs=[tab1, tab2]) Selection and Non-Selection Glyphs >>> p = figure(tools='box_select') >>> p.circle('mpg', 'cyl', source=cds_df, selection_color='red', nonselection_alpha=0.1) Hover Glyphs >>> hover = HoverTool(tooltips=None, mode='vline') >>> p3.add_tools(hover) Colormapping >>> color_mapper = CategoricalColorMapper( factors=['US', 'Asia', 'Europe'], palette=['blue', 'red', 'green']) >>> p3.circle('mpg', 'cyl', source=cds_df, color=dict(field='origin', transform=color_mapper), legend='Origin')) Linked Plots >>> from bokeh.io import output_file, show >>> output_file('my_bar_chart.html', mode='cdn') >>> from bokeh.models import ColumnDataSource >>> cds_df = ColumnDataSource(df) Data Also see Lists, NumPy & Pandas Under the hood, your data is converted to Column Data Sources. You can also do this manually: Customized Glyphs Inside Plot Area >>> p.legend.location = 'bottom_left' Outside Plot Area >>> r1 = p2.asterisk(np.array([1,2,3]), np.array([3,2,1]) >>> r2 = p2.line([1,2,3,4], [3,4,5,6]) >>> legend = Legend(items=[("One" , [p1, r1]),("Two" , [r2])], location=(0, -30)) >>> p.add_layout(legend, 'right') The Python interactive visualization library Bokeh enables high-performance visual presentation of large datasets in modern web browsers. Bokeh’s mid-level general purpose bokeh.plotting interface is centered around two main components: data and glyphs. The basic steps to creating plots with the bokeh.plotting interface are: 1. Prepare some data: Python lists, NumPy arrays, Pandas DataFrames and other sequences of values 2. Create a new plot 3. Add renderers for your data, with visual customizations 4. Specify where to generate the output 5. Show or save the results + = data glyphs plot >>> from bokeh.plotting import figure >>> from bokeh.io import output_file, show >>> x = [1, 2, 3, 4, 5] >>> y = [6, 7, 2, 4, 5] >>> p = figure(title="simple line example", x_axis_label='x', y_axis_label='y') >>> p.line(x, y, legend="Temp.", line_width=2) >>> output_file("lines.html") >>> show(p) Step 4 Step 2 Step 1 Step 5 Step 3 Renderers & Visual Customizations >>> p.legend.orientation = "horizontal" >>> p.legend.orientation = "vertical" >>> from bokeh.charts import Bar >>> p = Bar(df, stacked=True, palette=['red','blue']) Bar Chart Box Plot Histogram Scatter Plot >>> from bokeh.charts import BoxPlot >>> p = BoxPlot(df, values='vals', label='cyl', legend='bottom_right') >>> from bokeh.charts import Histogram >>> p = Histogram(df, title='Histogram') >>> from bokeh.charts import Scatter >>> p = Scatter(df, x='mpg', y ='hp', marker='square', xlabel='Miles Per Gallon', ylabel='Horsepower') >>> show(p1) >>> save(p1) >>> show(layout) >>> save(layout) Label 1 Label 2 Label 3 Histogram x-axis y-axis 2 Scatter Markers >>> p1.circle(np.array([1,2,3]), np.array([3,2,1]), fill_color='white') >>> p2.square(np.array([1.5,3.5,5.5]), [1,4,3], color='blue', size=1) Line Glyphs >>> p1.line([1,2,3,4], [3,4,5,6], line_width=2) >>> p2.multi_line(pd.DataFrame([[1,2,3],[5,6,7]]), pd.DataFrame([[3,4,5],[3,2,1]]), color="blue") 3 Glyphs Output4 Output to HTML File Notebook Output Show or Save Your Plots5 1 Legends Columns >>> from bokeh.layouts import columns >>> layout = column(p1,p2,p3) Linked Axes >>> p2.x_range = p1.x_range >>> p2.y_range = p1.y_range Linked Brushing >>> p4 = figure(plot_width = 100, tools='box_select,lasso_select') >>> p4.circle('mpg', 'cyl', source=cds_df) >>> p5 = figure(plot_width = 200, tools='box_select,lasso_select') >>> p5.circle('mpg', 'hp', source=cds_df) >>> layout = row(p4,p5) Nesting Rows & Columns >>>layout = row(column(p1,p2), p3) Legend Location Legend Orientation Legend Background & Border >>> p.legend.border_line_color = "navy" >>> p.legend.background_fill_color = "white" >>> import numpy as np >>> import pandas as pd >>> df = pd.DataFrame(np.array([[33.9,4,65, 'US'], [32.4,4,66, 'Asia'], [21.4,4,109, 'Europe']]), columns=['mpg','cyl', 'hp', 'origin'], index=['Toyota', 'Fiat', 'Volvo']) Also see Data Also see Data Embedding Statistical Charts With Bokeh Bokeh’s high-level bokeh.charts interface is ideal for quickly creating statistical charts Also see Data US Asia Europe