set title of matplotlib plot in python

To set the title of a plot in Matplotlib, you can use the title() method of the pyplot module. Here's an example code snippet showing how to set a title for a plot:

main.py
import matplotlib.pyplot as plt

# Create some data
x = [1, 2, 3, 4]
y = [1, 4, 2, 3]

# Plot the data
plt.plot(x, y)

# Set the title
plt.title("My Plot Title")

# Show the plot
plt.show()
190 chars
15 lines

In this code, we first import the pyplot module from Matplotlib. We then create some sample data, plot it using the plot() method, and finally set the title using the title() method. Finally, we show the plot using the show() method.

related categories

gistlibby LogSnag