我尝试使用matplotlib 2绘图(或更多)和同时显示带有消息的弹出框(以非顺序方式)。这似乎很容易,但我没有成功。 我尝试了两种方法:
如上面的两个链接所示,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)
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)
需要通常的绘图显示(可缩放,可调整大小等)。对于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')
...
>>>
在这种情况下,它是完美的,我得到了我想要的......除了(我可能太纯粹了!!!),在这种情况下,不可能用x-close角关闭msgbox。 .. 我将非常感谢关于所有这些故事的所有评论(线程不工作1.,plt和wx不能一起工作2.)并且如果需要仅使用“OK”按钮来关闭msgbox。