Description:
This program plots a time series line chart and uses annotations to highlight important events (e.g., spikes, drops, or milestones).
annotate()
adds text at specific data points.
Used to point out important events (like promotions or spikes).
An arrow or label improves chart storytelling.
Helps users understand sudden changes in data.
Program:
import matplotlib.pyplot as plt
# Sample time series data
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
sales = [100, 120, 130, 90, 150, 110]
# Plotting the line chart
plt.plot(months, sales, marker='o', color='blue', label='Monthly Sales')
# Annotate the highest point
max_value = max(sales)
max_index = sales.index(max_value)
plt.annotate('Peak Sale',
xy=(months[max_index], max_value),
xytext=(months[max_index], max_value + 10),
arrowprops=dict(facecolor='green', shrink=0.05))
# Annotate a drop
plt.annotate('Sales Drop',
xy=('Apr', 90),
xytext=('Mar', 110),
arrowprops=dict(facecolor='red', shrink=0.05))
# Add title and labels
plt.title('Sales Over Time with Key Events')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
plt.legend()
# Show plot
plt.show()
Output:
Trainings :
Data Science Training in Indore | Data Analytics Training in Indore | Python Training in Indore | Blockchain Training in Indore | React JS Training in Indore | Web Development Training in Indore | Full Stack Development Training in Indore |Free Courses and Resource :
Verbal Aptitude | Matplotlib Tutorials | Examples | Interview Questions | Pandas Tutorials | Projects | Interview Questions | OpenCV Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Dart | Python Data Structures and Algorithms | Rust Tutorials | Projects | Interview Questions | Aptitude Tests | HackerRank Python | Django | MongoDB Tutorials | Examples | Interview Questions | NumPy Practice Questions | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | React.js Tutorials | Verbal Ability Tutorial | MS Sql Server Tutorials | Examples | Interview Questions | Power BI Tutorials | Projects | Interview Questions | Example Dashboards | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial | HackerRank C++ Solutions | Tensor Flow | Pandas Practice Questions | Python Practice Questions | C++ Tutorials | Quantitative Ability Tutorial | Javascript | Node.js Tutorials | HackerRank SQL Solutions | HackerRank DSA Solutions | Verbal Aptitude 2 | HackerRank Java Solutions | HTML Tutorial | TCS NQT Mock Test Series | Reasoning Ability Tutorial | CodeChef Python Solutions | HackerRank C Program Solutions | Leetcode Python Solutions | SQL Practice Question | Matplotlib Practice Questions |Interview Questions :
Pandas Tutorials | Projects | Interview Questions | ExpressJS Tutorials | Projects | Interview Questions | Django | Python Tutorials by CodersDaily | Golang Tutorials | Projects | Interview Questions | Numpy Tutorials | Projects | Interview Questions | Django REST Framework Tutorial |Top Colleges in India :
Indian Institute of Technology Bombay | Jaypee University of Engineering and Technology - Guna |