File tree 1 file changed +25
-1
lines changed
1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change 85
85
}
86
86
87
87
88
+ def _safe_pyplot_import ():
89
+ """
90
+ Import and return ``pyplot``, correctly setting the backend if one is
91
+ already forced.
92
+ """
93
+ try :
94
+ import matplotlib .pyplot as plt
95
+ except ImportError : # Likely due to a framework mismatch.
96
+ current_framework = cbook ._get_running_interactive_framework ()
97
+ if current_framework is None :
98
+ raise # No, something else went wrong, likely with the install...
99
+ backend_mapping = {'qt5' : 'qt5agg' ,
100
+ 'qt4' : 'qt4agg' ,
101
+ 'gtk3' : 'gtk3agg' ,
102
+ 'wx' : 'wxagg' ,
103
+ 'tk' : 'tkagg' ,
104
+ 'macosx' : 'macosx' ,
105
+ 'headless' : 'agg' }
106
+ backend = backend_mapping [current_framework ]
107
+ rcParams ["backend" ] = mpl .rcParamsOrig ["backend" ] = backend
108
+ import matplotlib .pyplot as plt # Now this should succeed.
109
+ return plt
110
+
111
+
88
112
def register_backend (format , backend , description = None ):
89
113
"""
90
114
Register a backend for saving to a given file format.
@@ -3269,7 +3293,7 @@ def _update_view(self):
3269
3293
self .canvas .draw_idle ()
3270
3294
3271
3295
def configure_subplots (self , * args ):
3272
- from matplotlib import pyplot as plt
3296
+ plt = _safe_pyplot_import ()
3273
3297
tool = plt .subplot_tool (self .canvas .figure )
3274
3298
tool .figure .canvas .manager .show ()
3275
3299
You can’t perform that action at this time.
0 commit comments