- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 put text at the corner of an equal aspect figure in Python/Matplotlib?
To put text at the corner of an equal aspect figure in matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create a figure and a set of subplots, using subplots() method.
Create x data points using numpy.
Plot x on axis ax1, using plot() method.
Plot x and 2*x on ax2, using plot() method.
To put text in the corner of a figure use annotate() method for different axes.
To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, axes = plt.subplots(2) x = np.linspace(-2, 2, 10) axes[0].plot(x) axes[1].plot(x, 2*x) for ax in axes: ax.annotate('Straight Line', xy=(1, 0),xycoords='axes fraction', fontsize=10, horizontalalignment='right', verticalalignment='bottom') plt.show()
Output
- Related Articles
- How to put the title at the bottom of a figure in Matplotlib?
- How to put the Origin at the center of the cos curve in a figure in Python Matplotlib?
- How to show (0,0) on matplotlib graph at the bottom left corner?
- How to put text outside Python plots?
- How to compute the aspect ratio of an object in an image using OpenCV Python?
- How to autosize text in matplotlib Python?
- Setting the aspect ratio of a 3D plot in Matplotlib
- How to change the aspect ratio of an image in JavaFX?
- Tkinter - How to put an outline on a canvas text
- How to put a text in an image in OpenCV using C++?
- How do I extend the margin at the bottom of a figure in Matplotlib?
- How to maintain the aspect ratio of an element with CSS?
- How to put a title for a curved line in Python Matplotlib?
- How to put an outline on a canvas text on Tkinter?
- How to insert a small image on the corner of a plot with Matplotlib?

Advertisements