Python Bokeh Cheat Sheet

До загрузки: 30 сек.



Благодарим, что скачиваете у нас :)

Если, что - то:

  • Поделится ссылкой:
  • Документ найден в свободном доступе.
  • Загрузка документа - бесплатна.
  • Если нарушены ваши права, свяжитесь с нами.
Формат: pdf
Найдено: 09.09.2020
Добавлено: 30.09.2020
Размер: 0.25 Мб

Python For Data Science 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), BUDQJH  )>>> 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, "mBSORW" )
Components >>> from bokeh.embed import components>>> script, div = components(p)
Rows & Columns Layout
Rows>>> from bokeh.laRXWVLPSRUWURw>>> laRXW URZ SSS)
Grid Layout
>>> from bokeh.laRXWVLPSRUWJULGSORt>>> row1 = [p1,p2]>>> row2 = [p3]>>> laRXW JULGSORW >>SS@>S@@)
Tabbed Layout
>>> from bokeh.models.widgets import Panel, Tabs>>> tab1 = Panel(child=p1, title= "tab1" ) >>> tab2 = Panel(child=p2, title= "tab2" ) >>> laRXW 7DEV WDEV >WDEWDE@)
Selection and Non-Selection Glyphs >>> p = figure(tools= 'box_select' ) >>> p.circle( 'mpg' , 'cO' , 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' , 'cO' , source=cds_df, color=dict(field= 'origin' , transform=color_mapper), legend= 'Origin' )) Linked Plots
>>> from bokeh.io import output_file, show>>> output_file( 'mBEDUBFKDUWKWPO' , 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.arra >@ QSDUUD([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_laRXW OHJHQG '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]>>>  >]>>> p = figure(title= "simple line example" , x_axis_label= 'x' , BD[LVBODEHO= '' ) >>> p.line(x, OHJHQG= "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= 'cO' , legend= 'bottom_right' )
>>> from bokeh.charts import Histogram >>> p = Histogram(df, title= 'Histogram' )
>>> from bokeh.charts import Scatter >>> p = Scatter(df, x= 'mpg' , = 'hp' , marker= 'square' , xlabel= 'Miles Per Gallon' , ODEHO= 'Horsepower' ) >>> show(p1) >>> save(p1)>>> show(laRXW !!!VDYH ODout) Label 1
Label 2
Label 3
Histogram
x-axis
y-axis 2
Scatter Markers >>> p1.circle(np.arra >@ QSDUUD([3,2,1]), fill_color= 'white' ) >>> p2.square(np.arra >@ >@ 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.laRXWVLPSRUWFROXPQs>>> laRXW FROXPQ SSS)
Linked Axes>>> p2.x_range = p1.x_range>>> p2.BUDQJH S_range
Linked Brushing>>> p4 = figure(plot_width = 100, tools= 'box_select,lasso_select' ) >>> p4.circle( 'mpg' , 'cO' , source=cds_df) >>> p5 = figure(plot_width = 200, tools= 'box_select,lasso_select' ) >>> p5.circle( 'mpg' , 'hp' , source=cds_df) >>> laRXW URZ SS)
Nesting Rows & Columns>>>laRXW URZ FROXPQ SS S)
Legend Location Legend Orientation
Legend Background & Border
>>> p.legend.border_line_color = "nav" >>> p.legend.background_fill_color = "white"
>>> import numpDVQp>>> import pandas as pd>>> df = pd.DataFrame(np.arra >> 'US' ], [32.4,4,66, 'Asia' ], [21.4,4,109, 'Europe' ]]), columns=[ 'mpg' ,'cO' , 'hp', 'origin' ], index=[ 'ToRWD' , '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
A
sia
Europe

Сообщить о нарушении / Abuse

Все документы на сайте взяты из открытых источников, которые размещаются пользователями. Приносим свои глубочайшие извинения, если Ваш документ был опубликован без Вашего на то согласия.