Data visualization lab

Program 8

Write a Python program to explain working with bokeh line graph using Annotations and Legends. a) Write a Python program for plotting different types of plots using Bokeh.



from bokeh.plotting import figure, show
from bokeh.models import Span, Label

# Data
x = [1, 2, 3, 4, 5]
y = [2, 5, 8, 2, 7]

# Create a figure
p = figure(title="Bokeh Line Graph with Annotations & Legend", x_axis_label="X", y_axis_label="Y")

# Line with legend
p.line(x, y, line_width=2, color="blue", legend_label="Sample Line")

# Add annotation: horizontal line
hline = Span(location=5, dimension='width', line_color='red', line_width=2, line_dash='dashed')
p.add_layout(hline)

# Add text label
label = Label(x=3, y=8, text="Peak Value", text_color="green")
p.add_layout(label)

# Show legend
p.legend.title = "Legend"
p.legend.location = "top_left"

show(p)


  

Output :-

output


Comments

Replay !

0 Comments

Share Your Thoughts

Please enter your name
Please enter a valid email
Password must be at least 6 characters
Please enter your comment
Email Verification Required
We've sent a 6-digit verification code to . Please enter the code below to verify your email address.
Email Verified Successfully!
Your email has been verified. Would you like to proceed with posting your comment?

Type "YES" to confirm and post your comment, or click Cancel to skip posting.