在Matplotlib中隐藏轴外的区域

时间:2015-04-20 01:26:23

标签: python python-2.7 matplotlib

如何扩展绘图区域以占据整个画布并基本上删除图像中的灰色区域?我环顾四周,并没有找到任何解决方案,虽然可能是因为我不知道该怎么称呼这个区域所以搜索具有挑战性。

使用fig.tight_layout()会减少灰色,但不会将其删除。

from matplotlib import pyplot as plt

y = [1,3,5,6,7,8,12,13,15,15,16,25,26,28,29,36]
x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
fig, ax = plt.subplots(figsize=(8,4), dpi=85)

ax.stackplot(x, y, color='w', colors=('#ededed',))

ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
ax.set_ylim([0,max(y)*1.2])
ax.set_xlim([0,30])

plt.show()

enter image description here

1 个答案:

答案 0 :(得分:1)

指定创建Axes时<{1}}占用整个Figure -

Axes

enter image description here

现在,还有很多空间,例如,外部刻度标签;而Tkinter本身可能会做一些填充;但这和你fig = plt.figure() ax = fig.add_axes((0,0,1,1), frameon=False) ax.plot([2,5,4]) 一样大。 (Axes是图坐标中的范围。)

相关问题