from bokeh.plotting import figure, show # create a new plot with default tools, x and y ranges, and title p = figure(title="Simple Line Plot") # add a line renderer with legend and line thickness p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Line", line_width=2) # show the results show(p)
from bokeh.plotting import figure, show from bokeh.models import ColumnDataSource, HoverTool # create a data source with x and y columns source = ColumnDataSource(data={'x': [1, 2, 3, 4, 5], 'y': [6, 7, 2, 4, 5]}) # create a new plot with default tools, x and y ranges, and title p = figure(title="Scatter Plot with Hover Tool") # add a scatter marker renderer with hover tool and size mapper p.circle('x', 'y', size=10, source=source, hover_fill_color='firebrick', hover_alpha=0.5) # add a hover tool with x and y tooltips hover = HoverTool(tooltips=[('x', '@x'), ('y', '@y')]) p.add_tools(hover) # show the results show(p)In this example, a scatter plot is created using the bokeh.plotting figure method and a ColumnDataSource. The scatter marker renderer is customized with a hover tool and size mapper. A hover tool is added with x and y coordinate tooltips.