

The circle() function allows you to plot a scatter plot in Bokeh, as the following script demonstrates.Callbacks Creation & Widget Attribute Registration with Callback ¶

axis_label = 'Fare' hover = HoverTool () hover. vbar ( source = source, x = 'class', top = 'fare', width = 0.80, color = color_map ) f. tolist () color_map = factor_cmap ( field_name = 'class', palette = Spectral3, factors = classes ) f = figure ( plot_width = 500, plot_height = 500, x_range = classes ) f. Enter your email address below and I'll send a copy your way.įrom otting import figure, output_notebook, show from import HoverTool from otting import figure, output_notebook, show from import HoverTool from bokeh.models import ColumnDataSource from bokeh.palettes import Spectral3 from ansform import factor_cmap output_notebook () source = ColumnDataSource ( dataset ) classes = source. I put together a Python Developer Kit with over 100 pre-built Python scripts covering data structures, Pandas, NumPy, Seaborn, machine learning, file processing, web scraping and a whole lot more - and I want you to have it for free.

To do so, you can simply pass the Year and Life_Expectancy columns from the dataframe to the x and y attributes of the line() function.įrom otting import figure, output_notebook, show from import HoverTool from bokeh.models import ColumnDataSource from bokeh.palettes import Spectral3 from ansform import factor_cmap output_notebook () source = ColumnDataSource ( dataset ) classes = source. We’re going to filter the records for the US, then we’ll plot a line plot that displays yearly average life expectancy. It shows the spending in USD vs the average life expectancy per country from years 1970 to 2020. The script below imports the healthexp dataset from the Python seaborn module. Plotting Bokeh Plots using Pandas DataFramesĪ useful feature of the Bokeh library is that it allows you to plot data from a Pandas dataframes. When you run this script yourself, you can drag, zoom, and save the above plot using the controls displayed on the right-hand side of the plot. circle ( x, y, size = 5, color = 'red', legend_label = 'circle' ) f. line ( x, y, line_width = 2, color = "blue", legend_label = 'line' ) f. For example, clicking the line legend will hide the line plot, in the output of the following script.įinally, call the show() function on the figure object to display the chart.įrom otting import figure, output_notebook, show import numpy as np x = list ( range ( 11 )) y = output_notebook () f = figure ( plot_width = 400, plot_height = 400 ) f. Setting the legend.click_policy to hide allows you to hide legends by clicking on the legend values. You can then pass the line width, color, and the label for the legend to line_width, color, and legend_label attributes, respectively. Once this is done, you can plot any plot using this figure object.įor example, to make a line plot, use the line() function and pass it the x and y coordinates of your line. You can optionally pass the width and height of your plot here. Next, you need to create a figure object. Otherwise, the plot will be displayed in your default browser. If you want to display the chart inside a Python notebook, you must call the output_notebook() function. To plot a chart with Bokeh, you need to import a figure object, then import the output_notebook and show functions from the otting module.
#Bokeh python example how to#
In a later section, we’ll explain how to plot charts with the Pandas-Bokeh library. This section will show how to make charts with the Python Bokeh library.
