0% found this document useful (0 votes)
9 views

Text

Uploaded by

5rtys9c8fm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Text

Uploaded by

5rtys9c8fm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Import necessary libraries

from bokeh.plotting import figure, show, output_file


from bokeh.models import Span, Label, LabelSet, ColumnDataSource

# Prepare the output file


output_file("line_graph_with_annotations.html")

# Create a new figure


p = figure(title="Line Graph with Annotations and Legends",
x_axis_label='X-axis',
y_axis_label='Y-axis',
plot_width=800,
plot_height=400)

# Data for the line graph


x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y1 = [3, 7, 8, 5, 10, 3, 6, 7, 9, 10]
y2 = [2, 5, 6, 4, 8, 2, 4, 5, 7, 8]

# Add line renderers for the data


line1 = p.line(x, y1, legend_label="Line 1", line_width=2, color="blue")
line2 = p.line(x, y2, legend_label="Line 2", line_width=2, color="green")

# Add a horizontal annotation (Span)


hline = Span(location=5, dimension='width', line_color='red', line_width=1,
line_dash='dashed')
p.add_layout(hline)

# Add a label
label = Label(x=4, y=5, text='Threshold Line', text_color='red')
p.add_layout(label)

# Add labels for specific points using LabelSet


source = ColumnDataSource(data=dict(x=[3, 7], y=[8, 6], label=['Peak', 'Dip']))
labels = LabelSet(x='x', y='y', text='label', source=source, render_mode='canvas',
text_font_size='10pt')
p.add_layout(labels)

# Configure the legend


p.legend.title = "Lines"
p.legend.label_text_font_size = "12pt"
p.legend.location = "top_left"

# Show the plot


show(p)

You might also like