
- 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 add a variable to Python plt.title?
To add a varaible to Python plt.title(), we can take the following steps −
Create data points for x and y using numpy and num (is a variable) to calculate y and set this in title.
Plot x and y data points using plot() method with red color.
Set the title of the curve with variable num.
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, 1, 10) num = 2 y = num ** x plt.plot(x, y, c='red') plt.title(f"y=%d$^x$" % num) plt.show()
Output
- Related Articles
- How to add a variable in HTML?
- How to add a variable description in R?
- How to increase plt.title font size in Matplotlib?
- How to add a variable to the model in base R?
- How to declare a variable in Python?
- How to declare a global variable in Python?
- How to add a property to a JavaScript object using a variable as the name?
- How to pass a variable to an exception in Python?
- How to use a global variable in a Python function?
- How to detect whether a Python variable is a function?
- How to assign multiple values to a same variable in Python?
- How to get a variable name as a string in Python?
- How to declare a variable in Python without assigning a value to it?
- How to add a column to a MySQL table in Python?
- How to add new keys to a dictionary in Python?

Advertisements