- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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
How to annotate a range of the X-axis in Matplotlib?
To annotate a range of the X-axis in matplotlib, we can take the following steps −
- Set the figure size and adjust the padding between and around the subplots.
- Create xx and yy data points using numpy.
- Create a figure and a set of subplots.
- Plot xx and yy data points using plot() method.
- Set ylim of the axis.
- Use annotate method to place arrow heads and range tag name.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True xx = np.linspace(0, 10) yy = np.sin(xx) fig, ax = plt.subplots(1, 1) ax.plot(xx, yy) ax.set_ylim([-2, 2]) ax.annotate('', xy=(5,2), xytext=(8,2), xycoords='data', textcoords='data', arrowprops={'arrowstyle': '<|-|>'}, color='yellow') ax.annotate('Maximum Range', xy=(5,5), ha='center', va='center', color='red') plt.show()
Output
- Related Articles
- How to change the range of the X-axis and Y-axis in Matplotlib?
- How to enforce axis range in Matplotlib?
- How do I change the range of the X-axis with datetimes in Matplotlib?
- How to customize the X-axis in Matplotlib?
- How to add a second X-axis in Matplotlib?
- How to Annotate Matplotlib Scatter Plots?
- How to annotate a heatmap with text in Matplotlib?
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- How to shift a graph along the X-axis in matplotlib?
- How to customize X-axis ticks in Matplotlib?
- How to set X-axis values in Matplotlib Python?
- How to annotate the end of lines using Python and Matplotlib?
- How to set my xlabel at the end of X-axis in Matplotlib?
- How to add footnote under the X-axis using Matplotlib?
- How to add a second X-axis at the bottom of the first one in Matplotlib?

Advertisements