隐藏/不可见的 Matplotlib 图形 [英] Hide / Invisible Matplotlib figure
问题描述
我有一个问题,不知道难不难,但我试着用谷歌搜索答案.什么都不值得.
我将图形视为全局的,可以在所有线程中访问.
但是它出现在程序的开头,
我想在脚本的开头隐藏或使其不可见,然后在代码中的某一点使其可用或可见.
是否有任何Matplotlib,例如可见的False或类似的东西
我用这个:
plt.ion()无花果= plt.figure(可见=假)ax =fig.add_subplot(111)
预先感谢
如果要隐藏整个绘图窗口,并且正在使用tk后端-可以使用tkinter库中的Toplevel()小部件./p>
这是一个完整的例子:
from tkinter import *将numpy导入为np导入matplotlib.pyplot作为plt从 matplotlib.backends.backend_tkagg 导入 FigureCanvasTkAgg, NavigationToolbar2TkAgg图,(ax) = plt.subplots()x = np.linspace(0, 2 * np.pi)y = np.transpose([np.sin(x)])轴图(y)图 = 顶层()画布 = FigureCanvasTkAgg(fig, master=graph)canvas.get_tk_widget().pack()画布.show()工具栏= NavigationToolbar2TkAgg(画布,图形)工具栏.update()
通话:
graph.withdraw()
将隐藏绘图窗口,并且:
graph.deiconify()
将再次显示它.
I have a question, not sure if its difficult or not, but i tried to google the answer. nothing worthy.
I have figure as global, which can be accessed in all threads.
but it appears in the beginning of the program,
I want to hide or making it invisible in the starting of the script then at one point in the code make it available or visible.
Is there is any Matplotlib like visible False or something
i use this:
plt.ion()
fig = plt.figure(visible=False)
ax =fig.add_subplot(111)
Thanks in advance
In case you want to hide the entire plot window, and you are using the tk backend - you can use the Toplevel() widget from the tkinter library.
Here is a full example:
from tkinter import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
fig,(ax) = plt.subplots()
x = np.linspace(0, 2 * np.pi)
y = np.transpose([np.sin(x)])
ax.plot(y)
graph = Toplevel()
canvas = FigureCanvasTkAgg(fig, master=graph)
canvas.get_tk_widget().pack()
canvas.show()
toolbar = NavigationToolbar2TkAgg(canvas, graph)
toolbar.update()
Calling:
graph.withdraw()
will hide the plot window, and:
graph.deiconify()
will display it again.
这篇关于隐藏/不可见的 Matplotlib 图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!