我在调整图表 y 轴上数字标签的字体大小时遇到了一些问题。调整字体大小似乎只是调整图例框中的文字。
调整“轴”不起作用,因为我使用了 axes.ravel()
来帮助给出一组 2x2 的四个子图。
"axes.set_xlabel(fontsize='large', fontweight='bold') AttributeError: 'numpy.ndarray' object has no attribute 'set_xlabel'"
#The part of the code that creates the subplots.
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(40,20), squeeze=False, sharey=True)
axes = axes.ravel()
font = FontProperties()
font = {'weight' : 'bold','size' : 22}
plt.rc('font', **font)
#Then under here are the loops that create each subplot.
for each_subplot in range(0,4):
axes.set_xlabel(fontsize='large', fontweight='bold')
#Selecting the input data goes here, but I left it out.
最佳答案
axes
本身是一个轴数组。所以你想做:
for each_subplot in range(0,4):
axes[each_subplot].set_xlabel(fontsize='large', fontweight='bold')
或更简单:
for ax in axes:
ax.set_xlabel(fontsize='large', fontweight='bold')
关于python - 使用 Matplotlib 调整图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56115311/