[英]Hide the window frame around image plotted with matplotlib
我正在使用 matplotlib 来显示图片,但我想隐藏窗口框架。
我在plt.figure()
尝试了代码frameon=False
但窗口框架仍然存在。 只是背景颜色变成灰色。
这是代码和运行结果。 即使我在代码中添加了“frameon = False”,图片也显示在窗口中。
frameon
抑制图形框架。 您想要做的是在无框窗口中显示图形画布,无法从 matplotlib 中对其进行管理,因为该窗口是显示画布的 GUI 元素。 是否可以抑制帧以及如何进行抑制取决于操作系统和使用的 matplotlib 后端。
让我们考虑tk 后端。
import matplotlib
# make sure Tk backend is used
matplotlib.use("TkAgg")
import matplotlib.pyplot as plt
# turn navigation toolbar off
plt.rcParams['toolbar'] = 'None'
# create a figure and subplot
fig, ax = plt.subplots(figsize=(2,2))
#remove margins
fig.subplots_adjust(0,0,1,1)
# turn axes off
ax.axis("off")
# show image
im = plt.imread("https://upload.wikimedia.org/wikipedia/commons/8/87/QRCode.png")
ax.imshow(im)
# remove window frame
fig.canvas.manager.window.overrideredirect(1)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.