name axis in plt figure in python

To name the axis in a plot figure using the pyplot module in matplotlib, you can use the xlabel() and ylabel() functions.

Here's an example:

main.py
import matplotlib.pyplot as plt

# Data
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

# Plotting
plt.plot(x, y)

# Naming the axes
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

# Display the plot
plt.show()
201 chars
16 lines

In this example, xlabel('X-axis') and ylabel('Y-axis') are used to name the x-axis and y-axis, respectively.

You can customize the axis labels further by modifying the argument passed to the xlabel() and ylabel() functions.

related categories

gistlibby LogSnag