Matplotlib Axis Labels

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

plt.plot(x, y)
plt.xlabel('X Axis')  # Adding label to x-axis
plt.ylabel('Y Axis')  # Adding label to y-axis
plt.title('Basic Axis Labels')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)
plt.xlabel('X Axis', fontsize=14, color='red')  # Changing font size and color
plt.ylabel('Y Axis', fontsize=14, color='blue', rotation=45)  # Changing font size, color, and rotation
plt.title('Customized Axis Labels')
plt.show()
import matplotlib.pyplot as plt

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

plt.plot(x, y)
plt.xlabel('X Axis', labelpad=20)  # Adding extra space
plt.ylabel('Y Axis', labelpad=20)  # Adding extra space
plt.title('Axis Labels with Labelpad')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y1 = [1, 4, 9, 16, 25]
y2 = [1, 2, 3, 4, 5]

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 5))  # Create two subplots

ax1.plot(x, y1)
ax1.set_xlabel('X Axis 1')  # Adding label to x-axis of first subplot
ax1.set_ylabel('Y Axis 1')  # Adding label to y-axis of first subplot
ax1.set_title('Plot 1')

ax2.plot(x, y2)
ax2.set_xlabel('X Axis 2')  # Adding label to x-axis of second subplot
ax2.set_ylabel('Y Axis 2')  # Adding label to y-axis of second subplot
ax2.set_title('Plot 2')

plt.tight_layout()  # Adjust spacing to prevent overlap
plt.show()
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.xlabel(r'$\alpha$ (radians)', fontsize=14)  # LaTeX formatted X-axis label
plt.ylabel(r'$\beta$ (sin $\alpha$)', fontsize=14)  # LaTeX formatted Y-axis label

plt.show()
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.xlabel('X-axis Label', fontsize=14)
plt.ylabel('Y-axis Label', fontsize=14)

# Rotate labels by 45 degrees
plt.xticks(rotation=45)  # Rotate X-axis labels
plt.yticks(rotation=90)  # Rotate Y-axis labels

plt.show()