python - Matplotlib 标签显示不全

标签 python python-2.7 matplotlib

enter image description here

标签从图片上切掉了。您只能部分查看它们。 如何使标签完整显示?

pyplot.style.use('ggplot')

y = -30
x = 70
ax2 = pyplot.gca()

pyplot.plot(powerdemand, linewidth=2.0)
pyplot.plot(middle, linewidth=4.0)

ax2.set_xlabel('Time in s')
ax2.set_ylabel('Power consumption in MW')
pyplot.ylim(y,x)
# Place a legend to the right of this smaller figure.
pyplot.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=4,
           ncol=1, mode="expand", borderaxespad=0.)



for label in ax2.get_xticklabels()[::2]:
    label.set_visible(False)
for label in ax2.get_yticklabels()[::2]:
    label.set_visible(False)

pyplot.setp(ax2.get_yticklabels(), visible=True)

matplotlib.rcParams.update({'font.size': 23})

pyplot.savefig("/Users/user/Desktop/test.png")

最佳答案

保存无花果时尝试bbox_index:

pyplot.savefig("/Users/user/Desktop/test.png",bbox_index='tight')

关于python - Matplotlib 标签显示不全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30416238/

相关文章:

python - 完全删除 matplotlib 中曲面图上的网格?

python - pandas:将日期时间转换为月末

python group by,将列传递给聚合函数参数

python - 属性错误 : 'ParentedTree' object has no attribute 'label'

python - RabbitMQ basic_publish 是异步的吗?

python - Python中矩阵元素的双重求和

python - Pandas/matplotlib 并未绘制所有列数据

python-2.7 - 导入错误 : no module named pwd in app engine

python - 获取除numpy数组的第一个和最后一个元素之外的所有元素

python - 在 matplotlib 中已知 X 值的曲线上绘制标记