Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除matplotlib图中的灰色背景边框_Python_Matplotlib - Fatal编程技术网

Python 删除matplotlib图中的灰色背景边框

Python 删除matplotlib图中的灰色背景边框,python,matplotlib,Python,Matplotlib,我只想在matplotlib图中显示绘图图形(或imshow)。我可以使用pylab.axis(“关闭”)删除轴,但图中仍有一些灰色边框 我举个例子。我想删除所有,只保留imshow域(并保持缩放可用) 非常感谢。在您的情况下,您可能需要重塑图形窗口以适应内容的形状。对于方形窗口,您可以使用: fig = figure(figsize=(6, 6)) # width and height in inches fig.tight_layout(pad=0.5) # distance be

我只想在matplotlib图中显示绘图图形(或imshow)。我可以使用pylab.axis(“关闭”)删除轴,但图中仍有一些灰色边框

我举个例子。我想删除所有,只保留imshow域(并保持缩放可用)


非常感谢。

在您的情况下,您可能需要重塑图形窗口以适应内容的形状。对于方形窗口,您可以使用:

fig = figure(figsize=(6, 6))  # width and height in inches
fig.tight_layout(pad=0.5)     # distance betweeen the axis and the figure edge 
如果需要,请确保为轴标签保留一些空间。如果您只想更改背景颜色,那么@JoeKington的注释就是答案

尝试使用margins()函数(也是一种axis方法):

如果
fig
是您创建的图形,那么
fig.patch.set_alpha(0.0)
帮助是否可能重复?如果您要使用透明背景保存图形,请参阅@unutbu的注释。否则,必须有某种背景色。您可以使用
fig.set\u facecolor('white')
(或您喜欢的任何其他颜色)进行设置。似乎不必有任何类型的背景色:fig.set\u facecolor('None')工作正常。fig.set\u facecolor('None')不会删除此区域!都不是fig.patch.set_alpha(0.0)。。!它可以减少一点。但它对我的同龄人来说仍然相当大…没有办法将其完全从窗口中移除?它在右侧稍微缩小了一点,但我失去了图形中显示的中心。它还使缩放工具无法稳定图形大小和显示位置。。。奇怪!你能发布你的代码或类似的代码吗?也许你想要的图像也能帮上忙。