how to name axis in python

To name the x-axis and y-axis in Python using the matplotlib library, you can use the xlabel() and ylabel() functions. Here's an example:

main.py
import matplotlib.pyplot as plt

# Create some data
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 18]

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

# Name the x-axis and y-axis
plt.xlabel("X-axis")
plt.ylabel("Y-axis")

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

In this example, we first import the matplotlib.pyplot module. Then, we create some data for plotting. Next, we plot the data using the plot() function. Finally, we use the xlabel() and ylabel() functions to name the x-axis and y-axis, respectively.

related categories

gistlibby LogSnag