
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to put text outside Python plots?
To put text outside a plot, we can change the text position by changing the value of text_pos_x and text_pos_y
Steps
- Create data points for x and y.
- Initialize the text position of x and y.
- To plot x and y, use plot() method with color='red'.
- Use text() method to add text to figure.
- To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 5, 100) y = np.exp(x) text_pos_x = 0.60 text_pos_y = 0.50 plt.plot(x, y, c='red') plt.text(text_pos_x, text_pos_y, "$\mathit{y}=e^{x}$", fontsize=14, transform=plt.gcf().transFigure, color='green') plt.show()
Output
- Related Articles
- How to put a legend outside the plot with Pandas?
- How to write text outside plot using ggplot2 in R?
- How to put text at the corner of an equal aspect figure in Python/Matplotlib?
- How to prevent text select outside HTML5 canvas on double-click?
- Tkinter - How to put an outline on a canvas text
- How to put an outline on a canvas text on Tkinter?
- How to put a text in an image in OpenCV using C++?
- How to put comments inside a Python dictionary?
- How to make two plots side-by-side using Python?
- Superscript in Python plots
- How can Pygal be used to generate line plots in Python?
- How can Pygal be used to generate box plots in Python?
- How can Pygal be used to generate dot plots in Python?
- How can Pygal be used to generate Funnel plots in Python?
- How can Pygal be used to generate Gauge plots in Python?

Advertisements