Matplotlib:如何使背景透明? [英] Matplotlib: How to make the background transparent?

查看:919
本文介绍了Matplotlib:如何使背景透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了使绘图本身透明的方法,但是如何使背景透明? 没有Qt,有没有办法做到这一点? 我希望绘图位于背景窗口上方,例如,说我正在运行Chrome,我希望绘图位于镀铬窗口上方,其内容可见.

I came across ways to make the plot itself transparent, but how do I make the background transparent? Is there a way to do this without Qt? I want the plot to be over the background window, for example, say I'm running Chrome, I want the plot to be over the chrome window, with its contents visible.

推荐答案

透明性是window属性,因此将取决于使用中的后端和操作系统. Tkinter不太适合制作透明窗口,但是由于Qt的使用被排除在问题之外,因此您可以获得的最佳效果可能类似于以下内容,其中的窍门是使窗口中所有白色变为透明.

Transparency is a window property and will thus depend on the backend in use and the operating system. Tkinter is not well suited to make transparent windows, but since the use of Qt is excluded in the question, the best you can get is probably something like the following, where the trick would be to turn everything that is white in the window transparent.

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()

这篇关于Matplotlib:如何使背景透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆