python plot xlabel code example

Example 1: set axis labels python

# Basic syntax:
plt.xlabel("X axis label") # Add ", fontsize = #" to control fontsize
plt.ylabel("Y axis label")

# Example usage:
plt.plot(range(5))
plt.xlabel("X axis label")
plt.ylabel("Y axis label")
plt.title("Figure title", fontsize = 20)

# Note, xlabel and ylabel come from matplotlib.pyplot and plt is an 
# 	abbreviation for this, e.g. import matplotlib.pyplot as plt

Example 2: change name of axis matplotlib

plt.xlabel('X axis')
plt.ylabel('Y axis')

Example 3: pandas plot xlabel

ax = df1.plot()
ax.set_xlabel("x label")
ax.set_ylabel("y label")
plt.Show()