from bokeh.plotting import figure, output_file, show # Define data x = [1, 2, 3, 4, 5] y = [10, 20, 30, 40, 50] # Create plot p = figure(title="Line Plot", x_axis_label="X-axis", y_axis_label="Y-axis") # Add line glyph p.line(x, y, line_width=2, line_color='blue') # Output to HTML file output_file('line_plot.html') # Show plot show(p)
from bokeh.plotting import figure, output_file, show from bokeh.models import ColumnDataSource, HoverTool # Define data x = [1, 2, 3, 4, 5] y = [10, 20, 30, 40, 50] names = ['A', 'B', 'C', 'D', 'E'] # Create plot p = figure(title="Scatter Plot", x_axis_label="X-axis", y_axis_label="Y-axis", tools=[HoverTool(tooltips=[("Name", "@names"), ("X, Y", "($x, $y)")])]) # Add scatter glyph source = ColumnDataSource(data=dict(x=x, y=y, names=names)) p.scatter('x', 'y', source=source, size=10) # Output to HTML file output_file('scatter_plot.html') # Show plot show(p)In this example, the HoverTool class is used to add a tooltip that displays the name of each data point, as well as its X and Y coordinates. The ColumnDataSource class is used to provide the data to the plot and the glyphs. The package library used in this examples is Bokeh, as mentioned before.