change the font size of axis labels in matplotlib in python

To change the font size of axis labels in matplotlib in Python, you can use the fontsize parameter of the xlabel and ylabel functions. Here's an example:

main.py
import matplotlib.pyplot as plt

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

plt.plot(x, y)

# Change x-axis label font size
plt.xlabel('X-axis', fontsize=12)

# Change y-axis label font size
plt.ylabel('Y-axis', fontsize=12)

# Show the plot
plt.show()
266 chars
17 lines

In the above example, the fontsize parameter is set to 12 for both the x-axis and y-axis labels. You can adjust the value to change the font size according to your preference.

related categories

gistlibby LogSnag