Use of Pyplot in a GUI script

I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

This example for a app using WebAgg, but it doesn't use any pyplot
functions:
http://matplotlib.org/examples/pylab_examples/webapp_demo.html

The main thing to remember is that you:
1) Create a figure (matplotlib.figure.Figure)
2) Use the figure object's method of add the axes (e.g., fig.add_subplot)
3) use methods attached to the axes to do everything else

-p

···

On Tue, Apr 26, 2016 at 2:28 PM, Eric <eric.shain at gmail.com> wrote:

I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160516/7b23bd1b/attachment-0001.html>

In general, yes, you should avoid using pyplot when embedding. However,
that rule actually only needs to be strictly followed when you are
embedding the matplotlib's canvas into your own instantiated Window object.
If you are embedding GUI elements into a matplotlib figure window, you
actually can still utilize pyplot (but very carefully).

I suggest reading up my book:
http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

···

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com> wrote:

I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160516/dcbd82cf/attachment.html>

Ben,

I don?t really want a GUI application it this case. What I?m usually wanting is run pyplot with a file open dialog and a file save dialog. The file dialogs are important since I?m importing lots of json files and it would be a mess to try to type lots of long file names. I?ve tried several options including easygui, Tk and pyqt4. In theses cases, I can run them so long as I?m in an ipython console. However, as soon as I try to run from the terminal, I get a crash. I?ve managed by avoiding pyplot, but it is much nicer than using matplotlib without it.

Eric

···

On May 16, 2016, at 1:46 PM, Benjamin Root <ben.v.root at gmail.com> wrote:

In general, yes, you should avoid using pyplot when embedding. However, that rule actually only needs to be strictly followed when you are embedding the matplotlib's canvas into your own instantiated Window object. If you are embedding GUI elements into a matplotlib figure window, you actually can still utilize pyplot (but very carefully).

I suggest reading up my book: http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/96d5b8ca/attachment-0001.html>

The crashes are likely due to conflicts between the multiple gui event
loops, how ever with out a minimal example it is hard to say.

pyplot functions are mostly auto-generated and have the form

def foo(*args, **kwargs):
    retrun gca().foo(*args, **kwargs)

so anything you can do in pyplot you can do via the OO api. Just take a
look at the pyplot source for the functions you want to use and replace
`gca` with an Axes object or `gcf` with a Figure object.

Full Axes api docs: http://matplotlib.org/api/axes_api.html

Tom

···

On Wed, May 18, 2016 at 8:42 AM Eric's Gmail <eric.shain at gmail.com> wrote:

Ben,

I don?t really want a GUI application it this case. What I?m usually
wanting is run pyplot with a file open dialog and a file save dialog. The
file dialogs are important since I?m importing lots of json files and it
would be a mess to try to type lots of long file names. I?ve tried several
options including easygui, Tk and pyqt4. In theses cases, I can run them so
long as I?m in an ipython console. However, as soon as I try to run from
the terminal, I get a crash. I?ve managed by avoiding pyplot, but it is
much nicer than using matplotlib without it.

Eric

On May 16, 2016, at 1:46 PM, Benjamin Root <ben.v.root at gmail.com> wrote:

In general, yes, you should avoid using pyplot when embedding. However,
that rule actually only needs to be strictly followed when you are
embedding the matplotlib's canvas into your own instantiated Window object.
If you are embedding GUI elements into a matplotlib figure window, you
actually can still utilize pyplot (but very carefully).

I suggest reading up my book:
http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com> wrote:

I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when
I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should
avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com
<http://nabble.com>.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/0c175f78/attachment.html>

Thomas,

This is a minimal example. In this case I?m not even plotting:

from easygui import fileopenbox
import matplotlib.pyplot as plt
import numpy as np

ft = ["JSON", ["*.jsn", "*.json"]]
filename = fileopenbox(msg='Select JSON files',title='Import', filetypes=ft, multiple=False)
print(filename)
x = np.arange(10)
y = x**2

Trying to run this from the terminal (OS X, 10.11.4, Python 3.5.1) yield the following:

Erics-MacBook-Air:QTtest ericshain$ python plottest.py
2016-05-18 07:56:57.023 python[23268:3602317] -[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.038 python[23268:3602317] An uncaught exception was raised
2016-05-18 07:56:57.039 python[23268:3602317] -[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.039 python[23268:3602317] (
  0 CoreFoundation 0x00007fff8b1c94f2 __exceptionPreprocess + 178
  1 libobjc.A.dylib 0x00007fff8897af7e objc_exception_throw + 48
  2 CoreFoundation 0x00007fff8b2331ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
  3 CoreFoundation 0x00007fff8b139571 ___forwarding___ + 1009
  4 CoreFoundation 0x00007fff8b1390f8 _CF_forwarding_prep_0 + 120
  5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
  6 libtk8.5.dylib 0x0000000101594f91 Initialize + 1541
  7 _tkinter.cpython-35m-darwin.so 0x00000001003efded Tcl_AppInit + 77
  8 _tkinter.cpython-35m-darwin.so 0x00000001003ed7f9 _tkinter_create + 889
  9 libpython3.5m.dylib 0x00000001000679d9 PyCFunction_Call + 233
  10 libpython3.5m.dylib 0x00000001000f4cd7 PyEval_EvalFrameEx + 36647
  11 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  12 libpython3.5m.dylib 0x00000001000f5a07 PyEval_EvalCodeEx + 71
  13 libpython3.5m.dylib 0x00000001000426ba function_call + 186
  14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  15 libpython3.5m.dylib 0x000000010002b12c method_call + 140
  16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init + 81
  18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
  19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  20 libpython3.5m.dylib 0x00000001000edb9c PyEval_EvalFrameEx + 7660
  21 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  22 libpython3.5m.dylib 0x00000001000f3c75 PyEval_EvalFrameEx + 32453
  23 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode + 81
  25 libpython3.5m.dylib 0x00000001001247ee PyRun_FileExFlags + 206
  26 libpython3.5m.dylib 0x0000000100124a8f PyRun_SimpleFileExFlags + 447
  27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
  28 python 0x0000000100000e92 main + 418
  29 python 0x0000000100000cc4 start + 52
  30 ??? 0x0000000000000002 0x0 + 2
)
2016-05-18 07:56:57.039 python[23268:3602317] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500'
*** First throw call stack:
(
  0 CoreFoundation 0x00007fff8b1c94f2 __exceptionPreprocess + 178
  1 libobjc.A.dylib 0x00007fff8897af7e objc_exception_throw + 48
  2 CoreFoundation 0x00007fff8b2331ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
  3 CoreFoundation 0x00007fff8b139571 ___forwarding___ + 1009
  4 CoreFoundation 0x00007fff8b1390f8 _CF_forwarding_prep_0 + 120
  5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
  6 libtk8.5.dylib 0x0000000101594f91 Initialize + 1541
  7 _tkinter.cpython-35m-darwin.so 0x00000001003efded Tcl_AppInit + 77
  8 _tkinter.cpython-35m-darwin.so 0x00000001003ed7f9 _tkinter_create + 889
  9 libpython3.5m.dylib 0x00000001000679d9 PyCFunction_Call + 233
  10 libpython3.5m.dylib 0x00000001000f4cd7 PyEval_EvalFrameEx + 36647
  11 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  12 libpython3.5m.dylib 0x00000001000f5a07 PyEval_EvalCodeEx + 71
  13 libpython3.5m.dylib 0x00000001000426ba function_call + 186
  14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  15 libpython3.5m.dylib 0x000000010002b12c method_call + 140
  16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init + 81
  18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
  19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  20 libpython3.5m.dylib 0x00000001000edb9c PyEval_EvalFrameEx + 7660
  21 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  22 libpython3.5m.dylib 0x00000001000f3c75 PyEval_EvalFrameEx + 32453
  23 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode + 81
  25 libpython3.5m.dylib 0x00000001001247ee PyRun_FileExFlags + 206
  26 libpython3.5m.dylib 0x0000000100124a8f PyRun_SimpleFileExFlags + 447
  27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
  28 python 0x0000000100000e92 main + 418
  29 python 0x0000000100000cc4 start + 52
  30 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Eric

···

On May 18, 2016, at 7:52 AM, Thomas Caswell <tcaswell at gmail.com> wrote:

The crashes are likely due to conflicts between the multiple gui event loops, how ever with out a minimal example it is hard to say.

pyplot functions are mostly auto-generated and have the form

def foo(*args, **kwargs):
    retrun gca().foo(*args, **kwargs)

so anything you can do in pyplot you can do via the OO api. Just take a look at the pyplot source for the functions you want to use and replace `gca` with an Axes object or `gcf` with a Figure object.

Full Axes api docs: http://matplotlib.org/api/axes_api.html

Tom

On Wed, May 18, 2016 at 8:42 AM Eric's Gmail <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
Ben,

I don?t really want a GUI application it this case. What I?m usually wanting is run pyplot with a file open dialog and a file save dialog. The file dialogs are important since I?m importing lots of json files and it would be a mess to try to type lots of long file names. I?ve tried several options including easygui, Tk and pyqt4. In theses cases, I can run them so long as I?m in an ipython console. However, as soon as I try to run from the terminal, I get a crash. I?ve managed by avoiding pyplot, but it is much nicer than using matplotlib without it.

Eric

On May 16, 2016, at 1:46 PM, Benjamin Root <ben.v.root at gmail.com <mailto:ben.v.root at gmail.com>> wrote:

In general, yes, you should avoid using pyplot when embedding. However, that rule actually only needs to be strictly followed when you are embedding the matplotlib's canvas into your own instantiated Window object. If you are embedding GUI elements into a matplotlib figure window, you actually can still utilize pyplot (but very carefully).

I suggest reading up my book: http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com <http://nabble.com/>.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/03e7b574/attachment-0001.html>

Does that crash still occur if you don't import matplotlib? This doesn't
look at a matplotlib issue to me.

···

On Wed, May 18, 2016 at 6:02 AM, Eric's Gmail <eric.shain at gmail.com> wrote:

Thomas,

This is a minimal example. In this case I?m not even plotting:

from easygui import fileopenbox
import matplotlib.pyplot as plt
import numpy as np

ft = ["JSON", ["*.jsn", "*.json"]]
filename = fileopenbox(msg='Select JSON files',title='Import',
filetypes=ft, multiple=False)
print(filename)
x = np.arange(10)
y = x**2

Trying to run this from the terminal (OS X, 10.11.4, Python 3.5.1) yield
the following:

Erics-MacBook-Air:QTtest ericshain$ python plottest.py
2016-05-18 07:56:57.023 python[23268:3602317] -[NSApplication _setup:]:
unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.038 python[23268:3602317] An uncaught exception was
raised
2016-05-18 07:56:57.039 python[23268:3602317] -[NSApplication _setup:]:
unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.039 python[23268:3602317] (
0 CoreFoundation 0x00007fff8b1c94f2
__exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff8897af7e
objc_exception_throw + 48
2 CoreFoundation 0x00007fff8b2331ad
-[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8b139571
___forwarding___ + 1009
4 CoreFoundation 0x00007fff8b1390f8
_CF_forwarding_prep_0 + 120
5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
6 libtk8.5.dylib 0x0000000101594f91 Initialize +
1541
7 _tkinter.cpython-35m-darwin.so 0x00000001003efded Tcl_AppInit +
77
8 _tkinter.cpython-35m-darwin.so 0x00000001003ed7f9
_tkinter_create + 889
9 libpython3.5m.dylib 0x00000001000679d9
PyCFunction_Call + 233
10 libpython3.5m.dylib 0x00000001000f4cd7
PyEval_EvalFrameEx + 36647
11 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
12 libpython3.5m.dylib 0x00000001000f5a07
PyEval_EvalCodeEx + 71
13 libpython3.5m.dylib 0x00000001000426ba function_call +
186
14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
15 libpython3.5m.dylib 0x000000010002b12c method_call +
140
16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init +
81
18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
20 libpython3.5m.dylib 0x00000001000edb9c
PyEval_EvalFrameEx + 7660
21 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
22 libpython3.5m.dylib 0x00000001000f3c75
PyEval_EvalFrameEx + 32453
23 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode
+ 81
25 libpython3.5m.dylib 0x00000001001247ee
PyRun_FileExFlags + 206
26 libpython3.5m.dylib 0x0000000100124a8f
PyRun_SimpleFileExFlags + 447
27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
28 python 0x0000000100000e92 main + 418
29 python 0x0000000100000cc4 start + 52
30 ??? 0x0000000000000002 0x0 + 2
)
2016-05-18 07:56:57.039 python[23268:3602317] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication
_setup:]: unrecognized selector sent to instance 0x109c3c500'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8b1c94f2
__exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff8897af7e
objc_exception_throw + 48
2 CoreFoundation 0x00007fff8b2331ad
-[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8b139571
___forwarding___ + 1009
4 CoreFoundation 0x00007fff8b1390f8
_CF_forwarding_prep_0 + 120
5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
6 libtk8.5.dylib 0x0000000101594f91 Initialize +
1541
7 _tkinter.cpython-35m-darwin.so 0x00000001003efded Tcl_AppInit +
77
8 _tkinter.cpython-35m-darwin.so 0x00000001003ed7f9
_tkinter_create + 889
9 libpython3.5m.dylib 0x00000001000679d9
PyCFunction_Call + 233
10 libpython3.5m.dylib 0x00000001000f4cd7
PyEval_EvalFrameEx + 36647
11 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
12 libpython3.5m.dylib 0x00000001000f5a07
PyEval_EvalCodeEx + 71
13 libpython3.5m.dylib 0x00000001000426ba function_call +
186
14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
15 libpython3.5m.dylib 0x000000010002b12c method_call +
140
16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init +
81
18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call +
99
20 libpython3.5m.dylib 0x00000001000edb9c
PyEval_EvalFrameEx + 7660
21 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
22 libpython3.5m.dylib 0x00000001000f3c75
PyEval_EvalFrameEx + 32453
23 libpython3.5m.dylib 0x00000001000f5900
_PyEval_EvalCodeWithName + 2400
24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode
+ 81
25 libpython3.5m.dylib 0x00000001001247ee
PyRun_FileExFlags + 206
26 libpython3.5m.dylib 0x0000000100124a8f
PyRun_SimpleFileExFlags + 447
27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
28 python 0x0000000100000e92 main + 418
29 python 0x0000000100000cc4 start + 52
30 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Eric

On May 18, 2016, at 7:52 AM, Thomas Caswell <tcaswell at gmail.com> wrote:

The crashes are likely due to conflicts between the multiple gui event
loops, how ever with out a minimal example it is hard to say.

pyplot functions are mostly auto-generated and have the form

def foo(*args, **kwargs):
    retrun gca().foo(*args, **kwargs)

so anything you can do in pyplot you can do via the OO api. Just take a
look at the pyplot source for the functions you want to use and replace
`gca` with an Axes object or `gcf` with a Figure object.

Full Axes api docs: http://matplotlib.org/api/axes_api.html

Tom

On Wed, May 18, 2016 at 8:42 AM Eric's Gmail <eric.shain at gmail.com> wrote:

Ben,

I don?t really want a GUI application it this case. What I?m usually
wanting is run pyplot with a file open dialog and a file save dialog. The
file dialogs are important since I?m importing lots of json files and it
would be a mess to try to type lots of long file names. I?ve tried several
options including easygui, Tk and pyqt4. In theses cases, I can run them so
long as I?m in an ipython console. However, as soon as I try to run from
the terminal, I get a crash. I?ve managed by avoiding pyplot, but it is
much nicer than using matplotlib without it.

Eric

On May 16, 2016, at 1:46 PM, Benjamin Root <ben.v.root at gmail.com> wrote:

In general, yes, you should avoid using pyplot when embedding. However,
that rule actually only needs to be strictly followed when you are
embedding the matplotlib's canvas into your own instantiated Window object.
If you are embedding GUI elements into a matplotlib figure window, you
actually can still utilize pyplot (but very carefully).

I suggest reading up my book:
http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com> wrote:

I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter
file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal
when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot
using
matplotlib figure instead. First question is is it true that I should
avoid
any use of pyplot in a gui app? Second is that I find it hard to do
things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context:
http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com
<http://nabble.com/>.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/b3bf6950/attachment-0001.html>

If I comment out the matplotib.pyplot call it runs fine. If i comment out the easygui call it also doesn?t crash. I can import Figure from matplotlib OK.

Eric

···

On May 18, 2016, at 10:04 AM, Paul Hobson <pmhobson at gmail.com> wrote:

Does that crash still occur if you don't import matplotlib? This doesn't look at a matplotlib issue to me.

On Wed, May 18, 2016 at 6:02 AM, Eric's Gmail <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
Thomas,

This is a minimal example. In this case I?m not even plotting:

from easygui import fileopenbox
import matplotlib.pyplot as plt
import numpy as np

ft = ["JSON", ["*.jsn", "*.json"]]
filename = fileopenbox(msg='Select JSON files',title='Import', filetypes=ft, multiple=False)
print(filename)
x = np.arange(10)
y = x**2

Trying to run this from the terminal (OS X, 10.11.4, Python 3.5.1) yield the following:

Erics-MacBook-Air:QTtest ericshain$ python plottest.py
2016-05-18 07:56:57.023 python[23268:3602317] -[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.038 python[23268:3602317] An uncaught exception was raised
2016-05-18 07:56:57.039 python[23268:3602317] -[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500
2016-05-18 07:56:57.039 python[23268:3602317] (
  0 CoreFoundation 0x00007fff8b1c94f2 __exceptionPreprocess + 178
  1 libobjc.A.dylib 0x00007fff8897af7e objc_exception_throw + 48
  2 CoreFoundation 0x00007fff8b2331ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
  3 CoreFoundation 0x00007fff8b139571 ___forwarding___ + 1009
  4 CoreFoundation 0x00007fff8b1390f8 _CF_forwarding_prep_0 + 120
  5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
  6 libtk8.5.dylib 0x0000000101594f91 Initialize + 1541
  7 _tkinter.cpython-35m-darwin.so <http://tkinter.cpython-35m-darwin.so/> 0x00000001003efded Tcl_AppInit + 77
  8 _tkinter.cpython-35m-darwin.so <http://tkinter.cpython-35m-darwin.so/> 0x00000001003ed7f9 _tkinter_create + 889
  9 libpython3.5m.dylib 0x00000001000679d9 PyCFunction_Call + 233
  10 libpython3.5m.dylib 0x00000001000f4cd7 PyEval_EvalFrameEx + 36647
  11 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  12 libpython3.5m.dylib 0x00000001000f5a07 PyEval_EvalCodeEx + 71
  13 libpython3.5m.dylib 0x00000001000426ba function_call + 186
  14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  15 libpython3.5m.dylib 0x000000010002b12c method_call + 140
  16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init + 81
  18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
  19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  20 libpython3.5m.dylib 0x00000001000edb9c PyEval_EvalFrameEx + 7660
  21 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  22 libpython3.5m.dylib 0x00000001000f3c75 PyEval_EvalFrameEx + 32453
  23 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode + 81
  25 libpython3.5m.dylib 0x00000001001247ee PyRun_FileExFlags + 206
  26 libpython3.5m.dylib 0x0000000100124a8f PyRun_SimpleFileExFlags + 447
  27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
  28 python 0x0000000100000e92 main + 418
  29 python 0x0000000100000cc4 start + 52
  30 ??? 0x0000000000000002 0x0 + 2
)
2016-05-18 07:56:57.039 python[23268:3602317] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x109c3c500'
*** First throw call stack:
(
  0 CoreFoundation 0x00007fff8b1c94f2 __exceptionPreprocess + 178
  1 libobjc.A.dylib 0x00007fff8897af7e objc_exception_throw + 48
  2 CoreFoundation 0x00007fff8b2331ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
  3 CoreFoundation 0x00007fff8b139571 ___forwarding___ + 1009
  4 CoreFoundation 0x00007fff8b1390f8 _CF_forwarding_prep_0 + 120
  5 libtk8.5.dylib 0x000000010161c76d TkpInit + 472
  6 libtk8.5.dylib 0x0000000101594f91 Initialize + 1541
  7 _tkinter.cpython-35m-darwin.so <http://tkinter.cpython-35m-darwin.so/> 0x00000001003efded Tcl_AppInit + 77
  8 _tkinter.cpython-35m-darwin.so <http://tkinter.cpython-35m-darwin.so/> 0x00000001003ed7f9 _tkinter_create + 889
  9 libpython3.5m.dylib 0x00000001000679d9 PyCFunction_Call + 233
  10 libpython3.5m.dylib 0x00000001000f4cd7 PyEval_EvalFrameEx + 36647
  11 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  12 libpython3.5m.dylib 0x00000001000f5a07 PyEval_EvalCodeEx + 71
  13 libpython3.5m.dylib 0x00000001000426ba function_call + 186
  14 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  15 libpython3.5m.dylib 0x000000010002b12c method_call + 140
  16 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  17 libpython3.5m.dylib 0x0000000100080cc1 slot_tp_init + 81
  18 libpython3.5m.dylib 0x000000010007b964 type_call + 212
  19 libpython3.5m.dylib 0x000000010000de63 PyObject_Call + 99
  20 libpython3.5m.dylib 0x00000001000edb9c PyEval_EvalFrameEx + 7660
  21 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  22 libpython3.5m.dylib 0x00000001000f3c75 PyEval_EvalFrameEx + 32453
  23 libpython3.5m.dylib 0x00000001000f5900 _PyEval_EvalCodeWithName + 2400
  24 libpython3.5m.dylib 0x00000001000f5a61 PyEval_EvalCode + 81
  25 libpython3.5m.dylib 0x00000001001247ee PyRun_FileExFlags + 206
  26 libpython3.5m.dylib 0x0000000100124a8f PyRun_SimpleFileExFlags + 447
  27 libpython3.5m.dylib 0x000000010013d497 Py_Main + 3479
  28 python 0x0000000100000e92 main + 418
  29 python 0x0000000100000cc4 start + 52
  30 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Eric

On May 18, 2016, at 7:52 AM, Thomas Caswell <tcaswell at gmail.com <mailto:tcaswell at gmail.com>> wrote:

The crashes are likely due to conflicts between the multiple gui event loops, how ever with out a minimal example it is hard to say.

pyplot functions are mostly auto-generated and have the form

def foo(*args, **kwargs):
    retrun gca().foo(*args, **kwargs)

so anything you can do in pyplot you can do via the OO api. Just take a look at the pyplot source for the functions you want to use and replace `gca` with an Axes object or `gcf` with a Figure object.

Full Axes api docs: http://matplotlib.org/api/axes_api.html

Tom

On Wed, May 18, 2016 at 8:42 AM Eric's Gmail <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
Ben,

I don?t really want a GUI application it this case. What I?m usually wanting is run pyplot with a file open dialog and a file save dialog. The file dialogs are important since I?m importing lots of json files and it would be a mess to try to type lots of long file names. I?ve tried several options including easygui, Tk and pyqt4. In theses cases, I can run them so long as I?m in an ipython console. However, as soon as I try to run from the terminal, I get a crash. I?ve managed by avoiding pyplot, but it is much nicer than using matplotlib without it.

Eric

On May 16, 2016, at 1:46 PM, Benjamin Root <ben.v.root at gmail.com <mailto:ben.v.root at gmail.com>> wrote:

In general, yes, you should avoid using pyplot when embedding. However, that rule actually only needs to be strictly followed when you are embedding the matplotlib's canvas into your own instantiated Window object. If you are embedding GUI elements into a matplotlib figure window, you actually can still utilize pyplot (but very carefully).

I suggest reading up my book: http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

Cheers!
Ben Root

On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:
I've read that when writing a GUI application to avoid using pyplot. I
experienced this when I wrote a python script that called the tkinter file
dialog and then processed and plotted data. It would run when launched in
Ipython but would crash when run in the terminal. It ran in terminal when I
eliminated the file dialog and the file dialog code ran without the
plotting. I rewrote the script using pyqt4, and avoided using pyplot using
matplotlib figure instead. First question is is it true that I should avoid
any use of pyplot in a gui app? Second is that I find it hard to do things
in matplotlib that are easy in pyplot like drawing horizontal or vertical
lines and such. Is there documentation and code examples using the
matplotlib without pyplot?

Thanks, Eric

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
Sent from the matplotlib - users mailing list archive at Nabble.com <http://nabble.com/>.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/ba597c9d/attachment-0001.html>

What happens if you put the following lines at the top:

import matplotlib
matplotlib.use('tkagg')

Eric

···

On 2016/05/18 5:44 AM, Eric's Gmail wrote:

If I comment out the matplotib.pyplot call it runs fine. If i comment
out the easygui call it also doesn?t crash. I can import Figure from
matplotlib OK.

Eric

On May 18, 2016, at 10:04 AM, Paul Hobson <pmhobson at gmail.com >> <mailto:pmhobson at gmail.com>> wrote:

Does that crash still occur if you don't import matplotlib? This
doesn't look at a matplotlib issue to me.

On Wed, May 18, 2016 at 6:02 AM, Eric's Gmail <eric.shain at gmail.com >> <mailto:eric.shain at gmail.com>> wrote:

    Thomas,

    This is a minimal example. In this case I?m not even plotting:

    from easygui import fileopenbox
    import matplotlib.pyplot as plt
    import numpy as np

    ft = ["JSON", ["*.jsn", "*.json"]]
    filename = fileopenbox(msg='Select JSON files',title='Import',
    filetypes=ft, multiple=False)
    print(filename)
    x = np.arange(10)
    y = x**2

    Trying to run this from the terminal (OS X, 10.11.4, Python 3.5.1)
    yield the following:

    Erics-MacBook-Air:QTtest ericshain$ python plottest.py
    2016-05-18 07:56:57.023 python[23268:3602317] -[NSApplication
    _setup:]: unrecognized selector sent to instance 0x109c3c500
    2016-05-18 07:56:57.038 python[23268:3602317] An uncaught
    exception was raised
    2016-05-18 07:56:57.039 python[23268:3602317] -[NSApplication
    _setup:]: unrecognized selector sent to instance 0x109c3c500
    2016-05-18 07:56:57.039 python[23268:3602317] (
    0 CoreFoundation 0x00007fff8b1c94f2
    __exceptionPreprocess + 178
    1 libobjc.A.dylib 0x00007fff8897af7e
    objc_exception_throw + 48
    2 CoreFoundation 0x00007fff8b2331ad
    -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3 CoreFoundation 0x00007fff8b139571
    ___forwarding___ + 1009
    4 CoreFoundation 0x00007fff8b1390f8
    _CF_forwarding_prep_0 + 120
    5 libtk8.5.dylib 0x000000010161c76d TkpInit
    + 472
    6 libtk8.5.dylib 0x0000000101594f91
    Initialize + 1541
    7 _tkinter.cpython-35m-darwin.so
    <http://tkinter.cpython-35m-darwin.so/> 0x00000001003efded
    Tcl_AppInit + 77
    8 _tkinter.cpython-35m-darwin.so
    <http://tkinter.cpython-35m-darwin.so/> 0x00000001003ed7f9
    _tkinter_create + 889
    9 libpython3.5m.dylib 0x00000001000679d9
    PyCFunction_Call + 233
    10 libpython3.5m.dylib 0x00000001000f4cd7
    PyEval_EvalFrameEx + 36647
    11 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    12 libpython3.5m.dylib 0x00000001000f5a07
    PyEval_EvalCodeEx + 71
    13 libpython3.5m.dylib 0x00000001000426ba
    function_call + 186
    14 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    15 libpython3.5m.dylib 0x000000010002b12c
    method_call + 140
    16 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    17 libpython3.5m.dylib 0x0000000100080cc1
    slot_tp_init + 81
    18 libpython3.5m.dylib 0x000000010007b964
    type_call + 212
    19 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    20 libpython3.5m.dylib 0x00000001000edb9c
    PyEval_EvalFrameEx + 7660
    21 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    22 libpython3.5m.dylib 0x00000001000f3c75
    PyEval_EvalFrameEx + 32453
    23 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    24 libpython3.5m.dylib 0x00000001000f5a61
    PyEval_EvalCode + 81
    25 libpython3.5m.dylib 0x00000001001247ee
    PyRun_FileExFlags + 206
    26 libpython3.5m.dylib 0x0000000100124a8f
    PyRun_SimpleFileExFlags + 447
    27 libpython3.5m.dylib 0x000000010013d497 Py_Main
    + 3479
    28 python 0x0000000100000e92 main + 418
    29 python 0x0000000100000cc4 start + 52
    30 ??? 0x0000000000000002 0x0 + 2
    )
    2016-05-18 07:56:57.039 python[23268:3602317] *** Terminating app
    due to uncaught exception 'NSInvalidArgumentException', reason:
    '-[NSApplication _setup:]: unrecognized selector sent to instance
    0x109c3c500'
    *** First throw call stack:
    (
    0 CoreFoundation 0x00007fff8b1c94f2
    __exceptionPreprocess + 178
    1 libobjc.A.dylib 0x00007fff8897af7e
    objc_exception_throw + 48
    2 CoreFoundation 0x00007fff8b2331ad
    -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3 CoreFoundation 0x00007fff8b139571
    ___forwarding___ + 1009
    4 CoreFoundation 0x00007fff8b1390f8
    _CF_forwarding_prep_0 + 120
    5 libtk8.5.dylib 0x000000010161c76d TkpInit
    + 472
    6 libtk8.5.dylib 0x0000000101594f91
    Initialize + 1541
    7 _tkinter.cpython-35m-darwin.so
    <http://tkinter.cpython-35m-darwin.so/> 0x00000001003efded
    Tcl_AppInit + 77
    8 _tkinter.cpython-35m-darwin.so
    <http://tkinter.cpython-35m-darwin.so/> 0x00000001003ed7f9
    _tkinter_create + 889
    9 libpython3.5m.dylib 0x00000001000679d9
    PyCFunction_Call + 233
    10 libpython3.5m.dylib 0x00000001000f4cd7
    PyEval_EvalFrameEx + 36647
    11 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    12 libpython3.5m.dylib 0x00000001000f5a07
    PyEval_EvalCodeEx + 71
    13 libpython3.5m.dylib 0x00000001000426ba
    function_call + 186
    14 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    15 libpython3.5m.dylib 0x000000010002b12c
    method_call + 140
    16 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    17 libpython3.5m.dylib 0x0000000100080cc1
    slot_tp_init + 81
    18 libpython3.5m.dylib 0x000000010007b964
    type_call + 212
    19 libpython3.5m.dylib 0x000000010000de63
    PyObject_Call + 99
    20 libpython3.5m.dylib 0x00000001000edb9c
    PyEval_EvalFrameEx + 7660
    21 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    22 libpython3.5m.dylib 0x00000001000f3c75
    PyEval_EvalFrameEx + 32453
    23 libpython3.5m.dylib 0x00000001000f5900
    _PyEval_EvalCodeWithName + 2400
    24 libpython3.5m.dylib 0x00000001000f5a61
    PyEval_EvalCode + 81
    25 libpython3.5m.dylib 0x00000001001247ee
    PyRun_FileExFlags + 206
    26 libpython3.5m.dylib 0x0000000100124a8f
    PyRun_SimpleFileExFlags + 447
    27 libpython3.5m.dylib 0x000000010013d497 Py_Main
    + 3479
    28 python 0x0000000100000e92 main + 418
    29 python 0x0000000100000cc4 start + 52
    30 ??? 0x0000000000000002 0x0 + 2
    )
    libc++abi.dylib: terminating with uncaught exception of type
    NSException
    Abort trap: 6

    Eric

    On May 18, 2016, at 7:52 AM, Thomas Caswell <tcaswell at gmail.com >>> <mailto:tcaswell at gmail.com>> wrote:

    The crashes are likely due to conflicts between the multiple gui
    event loops, how ever with out a minimal example it is hard to say.

    pyplot functions are mostly auto-generated and have the form

    def foo(*args, **kwargs):
        retrun gca().foo(*args, **kwargs)

    so anything you can do in pyplot you can do via the OO api. Just
    take a look at the pyplot source for the functions you want to
    use and replace `gca` with an Axes object or `gcf` with a Figure
    object.

    Full Axes api docs: http://matplotlib.org/api/axes_api.html

    Tom

    On Wed, May 18, 2016 at 8:42 AM Eric's Gmail >>> <eric.shain at gmail.com <mailto:eric.shain at gmail.com>> wrote:

        Ben,

        I don?t really want a GUI application it this case. What I?m
        usually wanting is run pyplot with a file open dialog and a
        file save dialog. The file dialogs are important since I?m
        importing lots of json files and it would be a mess to try to
        type lots of long file names. I?ve tried several options
        including easygui, Tk and pyqt4. In theses cases, I can run
        them so long as I?m in an ipython console. However, as soon
        as I try to run from the terminal, I get a crash. I?ve
        managed by avoiding pyplot, but it is much nicer than using
        matplotlib without it.

        Eric

        On May 16, 2016, at 1:46 PM, Benjamin Root >>>> <ben.v.root at gmail.com <mailto:ben.v.root at gmail.com>> wrote:

        In general, yes, you should avoid using pyplot when
        embedding. However, that rule actually only needs to be
        strictly followed when you are embedding the matplotlib's
        canvas into your own instantiated Window object. If you are
        embedding GUI elements into a matplotlib figure window, you
        actually can still utilize pyplot (but very carefully).

        I suggest reading up my book:
        http://www.amazon.com/Interactive-Applications-using-Matplotlib-Benjamin/dp/1783988843/

        Cheers!
        Ben Root

        On Tue, Apr 26, 2016 at 5:28 PM, Eric <eric.shain at gmail.com >>>> <mailto:eric.shain at gmail.com>> wrote:

            I've read that when writing a GUI application to avoid
            using pyplot. I
            experienced this when I wrote a python script that
            called the tkinter file
            dialog and then processed and plotted data. It would run
            when launched in
            Ipython but would crash when run in the terminal. It ran
            in terminal when I
            eliminated the file dialog and the file dialog code ran
            without the
            plotting. I rewrote the script using pyqt4, and avoided
            using pyplot using
            matplotlib figure instead. First question is is it true
            that I should avoid
            any use of pyplot in a gui app? Second is that I find it
            hard to do things
            in matplotlib that are easy in pyplot like drawing
            horizontal or vertical
            lines and such. Is there documentation and code examples
            using the
            matplotlib without pyplot?

            Thanks, Eric

            --
            View this message in context:
            http://matplotlib.1069221.n5.nabble.com/Use-of-Pyplot-in-a-GUI-script-tp47030.html
            Sent from the matplotlib - users mailing list archive at
            Nabble.com <http://nabble.com/>.
            _______________________________________________
            Matplotlib-users mailing list
            Matplotlib-users at python.org
            <mailto:Matplotlib-users at python.org>
            https://mail.python.org/mailman/listinfo/matplotlib-users

        _______________________________________________
        Matplotlib-users mailing list
        Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
        https://mail.python.org/mailman/listinfo/matplotlib-users

    _______________________________________________
    Matplotlib-users mailing list
    Matplotlib-users at python.org <mailto:Matplotlib-users at python.org>
    https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

Awesome!

This works so long as I callout before the importing of pyplot.

Eric

···

On May 18, 2016, at 11:13 AM, Eric Firing <efiring at hawaii.edu> wrote:

matplotlib.use('tkagg')

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160518/1d577af3/attachment.html>

FWIW, I wrote a Tkinter-based GUI program several years ago where I
embedded a matplotlib canvas in my own window, and I used pyplot just
fine. I put it up on GitHub yesterday which you can use as an example (
https://github.com/swails/mdout_analyzer) in case it helps.

For me, also, the key ingredient was setting the Tk backend to avoid
competing mainloops for the different GUI toolkits. The reason I embedded
the matplotlib graphs in my own window is so that I could destroy those
windows when the main control window was closed (if you rely on matplotlib
to create the windows for you, you can't control that window as easily from
other parts of your application).

All the best,
Jason

···

On Wed, May 18, 2016 at 1:05 PM, Eric's Gmail <eric.shain at gmail.com> wrote:

Awesome!

This works so long as I callout before the importing of pyplot.

Eric

On May 18, 2016, at 11:13 AM, Eric Firing <efiring at hawaii.edu> wrote:

matplotlib.use('tkagg')

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jason M. Swails
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160519/027fefdd/attachment-0001.html>

Does that still work with current matplotlib? The import of pyplot triggers
the call to pylab_setup(), which causes matplotlib to assume that it will
be responsible for managing the windows.

It might also be that Tkinter might be the odd backend in this case and
that this wouldn't be portable to other backends. The tkagg backend has a
bunch of oddities that makes it different from the others.

···

On Thu, May 19, 2016 at 8:12 AM, Jason Swails <jason.swails at gmail.com> wrote:

FWIW, I wrote a Tkinter-based GUI program several years ago where I
embedded a matplotlib canvas in my own window, and I used pyplot just
fine. I put it up on GitHub yesterday which you can use as an example (
https://github.com/swails/mdout_analyzer) in case it helps.

For me, also, the key ingredient was setting the Tk backend to avoid
competing mainloops for the different GUI toolkits. The reason I embedded
the matplotlib graphs in my own window is so that I could destroy those
windows when the main control window was closed (if you rely on matplotlib
to create the windows for you, you can't control that window as easily from
other parts of your application).

All the best,
Jason

On Wed, May 18, 2016 at 1:05 PM, Eric's Gmail <eric.shain at gmail.com> > wrote:

Awesome!

This works so long as I callout before the importing of pyplot.

Eric

On May 18, 2016, at 11:13 AM, Eric Firing <efiring at hawaii.edu> wrote:

matplotlib.use('tkagg')

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Jason M. Swails

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160519/57296a35/attachment.html>