Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.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 如何在PLT中保存图像_Python_Matplotlib_Tkinter - Fatal编程技术网

Python 如何在PLT中保存图像

Python 如何在PLT中保存图像,python,matplotlib,tkinter,Python,Matplotlib,Tkinter,我试图使用matplotlib.pyplot保存结果图像,因为下面的代码工作正常,没有任何问题 import matplotlib.pyplot as plt I = image.astype(np.uint8) fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(I) plt.plot(marker_x, marker_y, color='yellow')# our circle ax.set_title('Macula') pl

我试图使用
matplotlib.pyplot
保存结果图像,因为下面的代码工作正常,没有任何问题

import matplotlib.pyplot as plt
I = image.astype(np.uint8)
fig = plt.figure() 
ax = fig.add_subplot(111)
ax.imshow(I) 
plt.plot(marker_x, marker_y, color='yellow')# our circle 
ax.set_title('Macula')
plt.savefig("J://uni//final project//res_image//marked_M.png")
fig.show()
这是我保存的图片
plt.savefig(“J://uni//final project//res\u image//marked\u M.png”)

黄色圆圈是一个
绘图
,如您所知,当我们使用
plt时。绘图
自动在主图片(如您在图片中看到的类似边距)和轴周围有一个空白

这是我的tkinter用户界面:


我想知道是否有任何方法可以裁剪这个恼人的空白区域,或者以另一种方式保存图像,从而去掉这个空白?

您可以使用matplotlib
透明
标志

plt.savefig("J://uni//final project//res_image//marked_M.png", transparent=True)

这会将图像保存为具有透明背景的png文件

为什么不将面部颜色设置为与GUI相同的颜色
fig.patch.set_facecolor('black')
@Novel
fig.patch.set_facecolor('black')
只需在我的pycharm上工作,但在我保存图像并在GUI中显示后,它不工作,问题仍然存在,正如@Halmon在下面所说的那样,我们可以这样做
plt.savefig(“J://uni//final project//res\u image//marked\u M.png”,transparent=True)
谢谢你的回答,我很感激。它很有效。