如何在matplotlib图中更改xticks的字体大小
要更改 xticks 的字体大小,我们可以使用 fontsize 参数。
步骤
- 导入 matplotlib 和 numpy 。
-
设置图形大小并调整子图之间和周围的间距。
-
使用numpy创建 x 和 y 数据点。
-
使用 plot() 方法绘制 x 和 y 数据点。
-
使用 xticks() 方法设置 xticks 的字体大小。
-
使用 show() 方法显示图形。
示例
from matplotlib import pyplot as plt
import numpy as np
# Set the figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
# x and y data points
x = np.linspace(-5, 5, 100)
y = np.sin(x)
plt.plot(x, y)
# Set the font size of xticks
plt.xticks(fontsize=25)
# Display the plot
plt.show()
输出
它会产生以下输出 −