Commit e7bab33
committed
Safely import pyplot if a GUI framework is already running.
`configure_subplots` now needs to import `pyplot` (because that's
how we can spin up a new figure as needed), but when relying on
embedding we could well reach that point with an already running
interactive framework, pyplot never imported, and an incompatible
rcParams["backend"] (which had not been read yet). For example, run
`examples/user_interfaces/embedding_in_tk_sgskip.py` with a non-tk
backend set in your matplotlibrc: clicking on the the configure_subplots
button triggers a "cannot load backend 'foo' which requires the 'foo'
interactive framework, as 'bar' is currently running".
Instead, use a helper to safely import pyplot when another interactive
framework may already be running. The list of frameworks that
`_get_running_interactive_framework` returns is fixed, so we can just
hardcode the mapping. (We are going to ignore the user-set
`rcParams["backend"]` anyways.)1 parent ce6ac2d commit e7bab33
1 file changed
+25
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
88 | 112 | | |
89 | 113 | | |
90 | 114 | | |
| |||
3269 | 3293 | | |
3270 | 3294 | | |
3271 | 3295 | | |
3272 | | - | |
| 3296 | + | |
3273 | 3297 | | |
3274 | 3298 | | |
3275 | 3299 | | |
| |||
0 commit comments