0

I try to display with matplotlib 2 plots (or more) and at the same time a popup box with a message (in a not sequential manner). It seems easy, but I do not succeed. I tryed 2 methods:

  1. Treads 1.a and 1.b.
  2. interactive/non-interactive mode in matplotlib.

As seen on the two links above, 1. is not working for me.

Concerning the 2.:

2.1 with interactive on

>>> 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 with interactive off

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

An usual plot display is needed (zoomable, resizable, etc). For 2.1 and 2.2, all is fine until the wx.App Class uses. Plot displays become not resizable etc ... and finally I am exited from python interpreter with error message ... Because I observes the problem comes when I start to use wx concomitantly to matplotlib, I decided to rather use 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')
...
>>> 

In this case, it is perfect, I obtained exactly what I wanted ... except (I am may be too purist !!!), in this case it is impossible to close the msgbox with the x-close corner ... I will very appreciate all remarks about all this story (threads not working 1., plt and wx not working together 2.) and if it is required to use only the 'OK' button to close the msgbox.

Community
  • 1
  • 1
servoz
  • 606
  • 9
  • 22
  • I guess wxpython is not a good solution for interactive session like you are doing unless you use PyCrust included in the wxPython demo as shell. Can you use some GUI elements in matplotlib (http://matplotlib.org/examples/widgets/index.html?highlight=widgets)? – otterb Apr 25 '15 at 12:31
  • Also for the wx dialog problem it's nothing to do with matplotlib interactive mode. I could confirm your wx dialog works fine in PyCrust. But it will not work in normal python shell. – otterb Apr 25 '15 at 12:40
  • Thank you for these comments. I will try it as soon as possible. – servoz Apr 27 '15 at 07:25

0 Answers0