Python 使用matplotlib显示两个(或更多)绘图,同时显示一个弹出消息框

Python 使用matplotlib显示两个(或更多)绘图,同时显示一个弹出消息框,python,multithreading,matplotlib,wxpython,Python,Multithreading,Matplotlib,Wxpython,我尝试使用matplotlib 2绘图(或更多)同时显示带有消息的弹出框(非顺序方式)。这似乎很容易,但我没有成功。 我尝试了两种方法: 踩踏和踩踏 matplotlib中的交互/非交互模式 如上面两个链接所示,1。他不适合我 关于第2条: 2.1带互动功能 >>> import numpy as np >>> import matplotlib.pyplot as plt >>> import wx >>> plt.ion

我尝试使用matplotlib 2绘图(或更多)同时显示带有消息的弹出框(非顺序方式)。这似乎很容易,但我没有成功。 我尝试了两种方法:

  • 踩踏和踩踏
  • matplotlib中的交互/非交互模式
  • 如上面两个链接所示,1。他不适合我

    关于第2条:

    2.1带互动功能

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> import wx
    >>> plt.ion()
    >>> for i in range(3):
    ...     plt.figure()
    ...     plt.plot(np.random.rand(10))
    ... 
    <matplotlib.figure.Figure object at 0x2c56e90>
    [<matplotlib.lines.Line2D object at 0x3ab7090>]
    <matplotlib.figure.Figure object at 0x3ab7310>
    [<matplotlib.lines.Line2D object at 0x3dff310>]
    <matplotlib.figure.Figure object at 0x3dff590>
    [<matplotlib.lines.Line2D object at 0x42372d0>]
    >>> qualPara = wx.App(False)
    >>> dlg = wx.MessageDialog(None, "toto", 'titi', wx.OK | wx.ICON_INFORMATION |wx.STAY_ON_TOP, pos=(-1,-1))
    >>> dlg.ShowModal()
    5100
    >>> 
    (python:6268): Gdk-ERROR **: The program 'python' received an X Window System error.
    This probably reflects a bug in the program.
    The error was 'BadWindow (invalid Window parameter)'.
      (Details: serial 1691 error_code 3 request_code 15 minor_code 0)
      (Note to programmers: normally, X errors are reported asynchronously;
       that is, you will receive the error a while after causing it.
       To debug your program, run it with the --sync command line
       option to change this behavior. You can then get a meaningful
       backtrace from your debugger if you break on the gdk_x_error() function.)
    Trace/BPT trap (core dumped)
    
    >>将numpy作为np导入
    >>>将matplotlib.pyplot作为plt导入
    >>>导入wx
    >>>plt.ion()
    >>>对于范围(3)中的i:
    ...     plt.图()
    ...     plt.plot(np.rand(10))
    ... 
    []
    []
    []
    >>>qualPara=wx.App(False)
    >>>dlg=wx.MessageDialog(无,“toto”,“titi”,wx.OK | wx.ICON|u信息| wx.STAY|u在顶部,位置=(-1,-1))
    >>>dlg.ShowModal()
    5100
    >>> 
    (python:6268):Gdk错误**:程序“python”收到一个X窗口系统错误。
    这可能反映了程序中的错误。
    错误为“BadWindow(无效的窗口参数)”。
    (详细信息:序列1691错误\u代码3请求\u代码15次要\u代码0)
    (程序员注意:通常,X错误是异步报告的;
    也就是说,在导致错误后一段时间,您将收到该错误。
    要调试程序,请使用--sync命令行运行它
    选项来更改此行为。然后您可以获得有意义的
    如果中断gdk_x_error()函数,则从调试器进行回溯。)
    跟踪/BPT陷阱(堆芯倾倒)
    
    2.2带“交互式关闭”

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> import wx
    >>> plt.ioff()
    >>> for i in range(3):
    ...     plt.figure()
    ...     plt.plot(np.random.rand(10))
    ... 
    <matplotlib.figure.Figure object at 0x1f79e90>
    [<matplotlib.lines.Line2D object at 0x2cc0410>]
    <matplotlib.figure.Figure object at 0x2cc0690>
    [<matplotlib.lines.Line2D object at 0x2ce9110>]
    <matplotlib.figure.Figure object at 0x2ce9390>
    [<matplotlib.lines.Line2D object at 0x30b7ed0>]
    >>> plt.show(block=False)
    >>> qualPara = wx.App(True)
    >>> dlg = wx.MessageDialog(None, "toto", 'titi', wx.OK | wx.ICON_INFORMATION |wx.STAY_ON_TOP, pos=(-1,-1)
    ... )
    >>> dlg.ShowModal()
    >>> 
    (python:6315): Gdk-ERROR **: The program 'python' received an X Window System error.
    This probably reflects a bug in the program.
    The error was 'BadWindow (invalid Window parameter)'.
      (Details: serial 3737 error_code 3 request_code 15 minor_code 0)
      (Note to programmers: normally, X errors are reported asynchronously;
       that is, you will receive the error a while after causing it.
       To debug your program, run it with the --sync command line
       option to change this behavior. You can then get a meaningful
       backtrace from your debugger if you break on the gdk_x_error() function.)
    Trace/BPT trap (core dumped)
    
    >>将numpy作为np导入
    >>>将matplotlib.pyplot作为plt导入
    >>>导入wx
    >>>plt.ioff()
    >>>对于范围(3)中的i:
    ...     plt.图()
    ...     plt.plot(np.rand(10))
    ... 
    []
    []
    []
    >>>plt.show(块=假)
    >>>qualPara=wx.App(真)
    >>>dlg=wx.MessageDialog(无,“toto”和“titi”,wx.OK | wx.ICON|u信息| wx.STAY|u在顶部,位置=(-1,-1)
    ... )
    >>>dlg.ShowModal()
    >>> 
    (python:6315):Gdk错误**:程序“python”收到一个X窗口系统错误。
    这可能反映了程序中的错误。
    错误为“BadWindow(无效的窗口参数)”。
    (详细信息:串行3737错误\u代码3请求\u代码15次要\u代码0)
    (程序员注意:通常,X错误是异步报告的;
    也就是说,在导致错误后一段时间,您将收到该错误。
    要调试程序,请使用--sync命令行运行它
    选项来更改此行为。然后您可以获得有意义的
    如果中断gdk_x_error()函数,则从调试器进行回溯。)
    跟踪/BPT陷阱(堆芯倾倒)
    
    需要常规的绘图显示(可缩放、可调整大小等)。对于2.1和2.2,在wx.App类使用之前一切正常。打印显示无法调整大小等。。。最后,我带着错误消息从python解释器中退出。。。 因为我发现问题是在我开始同时使用wx和matplotlib时出现的,所以我决定使用easygui.msgbox:

    >>> import numpy as np
    >>> import matplotlib.pyplot as plt
    >>> from easygui import msgbox
    >>> plt.ioff()
    >>> for i in range(3):
    ...     plt.figure()
    ...     plt.plot(np.random.rand(10))
    ... 
    <matplotlib.figure.Figure object at 0x3c220d0>
    [<matplotlib.lines.Line2D object at 0x3f8b950>]
    <matplotlib.figure.Figure object at 0x3f8bbd0>
    [<matplotlib.lines.Line2D object at 0x421b350>]
    <matplotlib.figure.Figure object at 0x421b5d0>
    [<matplotlib.lines.Line2D object at 0x424b150>]
    >>> plt.show(block=False)
    >>> if msgbox("toto",'titi') == 'OK':
    ...     plt.close('all')
    ...
    >>> 
    
    >>将numpy作为np导入
    >>>将matplotlib.pyplot作为plt导入
    >>>从easygui导入msgbox
    >>>plt.ioff()
    >>>对于范围(3)中的i:
    ...     plt.图()
    ...     plt.plot(np.rand(10))
    ... 
    []
    []
    []
    >>>plt.show(块=假)
    >>>如果msgbox(“toto”,“titi”)=“OK”:
    ...     plt.close(“全部”)
    ...
    >>> 
    
    在这种情况下,它是完美的,我得到了我想要的。。。除了(我可能太纯粹了!!!),在这种情况下,不可能用x-close角关闭msgbox。。。
    我将非常感谢所有关于这个故事的评论(线程不工作1,plt和wx不工作2。),如果只需要使用“OK”按钮关闭msgbox。

    我想wxpython不是像您这样的交互式会话的好解决方案,除非您使用wxpython演示中包含的PyCastle作为shell。能否在matplotlib()中使用一些GUI元素?同样,对于wx对话框问题,与matplotlib交互模式无关。我可以确认你的wx对话框在PyCastle中运行良好。但是它在普通的python shell中无法工作。谢谢您的评论。我会尽快试一试。