Bokeh is a powerful library for creating interactive visualizations in Python. To plot multiple lines on a single graph using Bokeh, you can use the figure()
function and add multiple line()
glyphs to the figure. Here’s a step-by-step guide:
1. Installation
If you don’t have Bokeh installed, you can install it using pip:
pip install bokeh
2. Basic Example
Here’s a simple example of how to plot multiple lines on a graph using Bokeh:
In this example:
figure()
creates a new plot with specified title and axis labels.p.line()
is used to add lines to the plot. The parameters include the x-values, y-values, line width, color, and legend label for each line.output_file("multiple_lines.html")
specifies the output file where the plot will be saved.show(p)
displays the plot in a web browser.
3. Adding Markers and Customizing the Plot
You can further customize your plot by adding markers, changing line styles, and more.
In this example:
line_dash="dashed"
andline_dash="dotted"
change the line styles.marker="circle"
andmarker="square"
add markers to the lines.
4. Summary
Plotting multiple lines on a graph using Bokeh is straightforward. By using the figure()
function and adding multiple line()
glyphs, you can create complex and informative visualizations. Bokeh provides flexibility in customizing the appearance of the plot, including line styles, colors, and markers.