|
11 | 11 | from .optpkg import optional_package |
12 | 12 | from .orientations import aff2axcodes, axcodes2ornt |
13 | 13 |
|
14 | | -plt, _, _ = optional_package('matplotlib.pyplot') |
15 | | -mpl_img, _, _ = optional_package('matplotlib.image') |
16 | | -mpl_patch, _, _ = optional_package('matplotlib.patches') |
17 | | - |
18 | 14 |
|
19 | 15 | class OrthoSlicer3D(object): |
20 | 16 | """Orthogonal-plane slicer. |
@@ -59,6 +55,12 @@ def __init__(self, data, affine=None, axes=None, cmap='gray', |
59 | 55 | figsize : tuple |
60 | 56 | Figure size (in inches) to use if axes are None. |
61 | 57 | """ |
| 58 | + # Nest imports so that matplotlib.use() has the appropriate |
| 59 | + # effect in testing |
| 60 | + plt, _, _ = optional_package('matplotlib.pyplot') |
| 61 | + mpl_img, _, _ = optional_package('matplotlib.image') |
| 62 | + mpl_patch, _, _ = optional_package('matplotlib.patches') |
| 63 | + |
62 | 64 | data = np.asanyarray(data) |
63 | 65 | if data.ndim < 3: |
64 | 66 | raise ValueError('data must have at least 3 dimensions') |
@@ -200,11 +202,13 @@ def __init__(self, data, affine=None, axes=None, cmap='gray', |
200 | 202 | def show(self): |
201 | 203 | """Show the slicer in blocking mode; convenience for ``plt.show()`` |
202 | 204 | """ |
| 205 | + plt, _, _ = optional_package('matplotlib.pyplot') |
203 | 206 | plt.show() |
204 | 207 |
|
205 | 208 | def close(self): |
206 | 209 | """Close the viewer figures |
207 | 210 | """ |
| 211 | + plt, _, _ = optional_package('matplotlib.pyplot') |
208 | 212 | for f in self._figs: |
209 | 213 | plt.close(f) |
210 | 214 | for link in self._links: |
|
0 commit comments