- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Annotate Time Series plot in Matplotlib
To annotate time series plot in matplotlib, we can take the following steps −
Create lists for time and numbers.
Using subplots() method, create a figure and a set of subplots.
Using plot_date() method, plot the data that contains dates with linestyle "-.".
Annotate a point in the plot using annotate() method.
Date ticklabels often overlap, so it is useful to rotate them and right-align them.
To display the figure, use show() method.
import datetime as dt from matplotlib import pyplot as plt, dates as mdates plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = [dt.datetime(2021, 1, 1), dt.datetime(2021, 1, 2), dt.datetime(2021, 1, 3), dt.datetime(2021, 1, 4)] y = [1, 3, 2, 5] fig, ax = plt.subplots() ax.plot_date(x, y, linestyle='-.') ax.annotate('Point', (mdates.date2num(x), y), xytext=(15, 15), textcoords='offset points', arrowprops=dict(arrowstyle='-|>')) fig.autofmt_xdate() plt.show()
- Plot multiple time-series DataFrames into a single plot using Pandas (Matplotlib)
- How can I plot two different spaced time series on one same plot in Python Matplotlib?
- How to plot a time series array, with confidence intervals displayed in Python? (Matplotlib)
- How to plot two Pandas time series on the same plot with legends and secondary Y-axis in Matplotlib?
- How to annotate the points on a scatter plot with automatically placed arrows in Matplotlib?
- How to plot a time series in Python?
- How to create a time series plot in R without time vector?
- Python - Create a Time Series Plot using Line Plot with Seaborn
- Moving X-axis in Matplotlib during real-time plot
- How to plot events on time using Matplotlib?
- How to plot Time Zones in a map in Matplotlib
- Python - Create a Time Series Plot with multiple columns using Line Plot
- How to plot multiple time series using ggplot2 in R?
- How to plot time series data with labels in R?
- How to annotate a heatmap with text in Matplotlib?