python - 使用 Matplotlib 调整图形

标签 python python-3.x matplotlib

我在调整图表 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/

相关文章:

python - 如何从像素矩阵显示图像?

Python如何在不删除已有内容的情况下继续写入文件

python - 填充动画中的图形之间

python - 在散点图中显示方向箭头

c++ - 简单的十六进制/ float 转换

python - 替换DataFrame中的某些数字

python - 当名称从 "application"更改时,Gunicorn 找不到应用程序

python - 平面算法之间的角度太慢

python - 如何将列表或显示剪切为多个部分

python - 在 Python 中绘制曲线