【问题标题】:Matplotlib: How to make the background transparent?Matplotlib:如何使背景透明?
【发布时间】:2016-07-19 20:16:28
【问题描述】:

我遇到了使情节本身透明的方法,但是如何使背景透明? 有没有办法在没有 Qt 的情况下做到这一点? 我希望绘图位于背景窗口上方,例如,假设我正在运行 Chrome,我希望绘图位于 chrome 窗口上方,并且其内容可见。

【问题讨论】:

标签: python matplotlib heatmap


【解决方案1】:

透明度是一个窗口属性,因此取决于使用的后端和操作系统。 Tkinter 不太适合制作透明窗口,但由于问题中排除了 Qt 的使用,因此您可以获得的最佳效果可能类似于以下内容,其中诀窍是将窗口中所有白色的东西都变成透明的。

import matplotlib
# make sure Tk backend is used
matplotlib.use("TkAgg")  
import matplotlib.pyplot as plt

# create a figure and some subplots
fig, ax = plt.subplots(figsize=(4,2))
ax.plot([2,3,5,1])
fig.tight_layout()

win = plt.gcf().canvas.manager.window

win.lift()
win.attributes("-topmost", True)
win.attributes("-transparentcolor", "white")

plt.show()

【讨论】:

  • 如何让matplot图透明
  • 尝试此操作时出现以下错误:tkinter.TclError: bad attribute "-transparentcolor": must be -alpha, -topmost, -zoomed, -fullscreen, or -type跨度>
  • 出现错误,AttributeError: 'FigureCanvasAgg' object has no attribute 'manager'
【解决方案2】:

如果将绘图保存为图像,则可以将背景设置为透明

myploy.savefig('plotname.png', transparent=True)

【讨论】:

    猜你喜欢
    • 2020-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 2015-08-06
    • 2011-09-17
    • 2011-02-18
    • 2016-10-24
    • 1970-01-01
    相关资源
    最近更新 更多