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')
@Novelfig.patch.set_facecolor('black')
只需在我的pycharm上工作,但在我保存图像并在GUI中显示后,它不工作,问题仍然存在,正如@Halmon在下面所说的那样,我们可以这样做plt.savefig(“J://uni//final project//res\u image//marked\u M.png”,transparent=True)
谢谢你的回答,我很感激。它很有效。