@@ -43,10 +43,11 @@ def new_figure_manager_given_figure(num, figure):
43
43
# https://github.com/ipython/ipython/issues/1612
44
44
# https://github.com/matplotlib/matplotlib/issues/835
45
45
46
- if not hasattr (figure , ' show' ):
46
+ if not hasattr (figure , " show" ):
47
47
# Queue up `figure` for display
48
48
figure .show = lambda * a : display (
49
- figure , metadata = _fetch_figure_metadata (figure ))
49
+ figure , metadata = _fetch_figure_metadata (figure )
50
+ )
50
51
51
52
# If matplotlib was manually set to non-interactive mode, this function
52
53
# should be a no-op (otherwise we'll generate duplicate plots, since a user
@@ -89,14 +90,14 @@ def show(close=None, block=None):
89
90
for figure_manager in Gcf .get_all_fig_managers ():
90
91
display (
91
92
figure_manager .canvas .figure ,
92
- metadata = _fetch_figure_metadata (figure_manager .canvas .figure )
93
+ metadata = _fetch_figure_metadata (figure_manager .canvas .figure ),
93
94
)
94
95
finally :
95
96
show ._to_draw = []
96
97
# only call close('all') if any to close
97
98
# close triggers gc.collect, which can be slow
98
99
if close and Gcf .get_all_fig_managers ():
99
- matplotlib .pyplot .close (' all' )
100
+ matplotlib .pyplot .close (" all" )
100
101
101
102
102
103
# This flag will be reset by draw_if_interactive when called
@@ -176,8 +177,8 @@ def configure_inline_support(shell, backend):
176
177
if cfg not in shell .configurables :
177
178
shell .configurables .append (cfg )
178
179
179
- if backend in (' inline' , ' module://matplotlib_inline.backend_inline' ):
180
- shell .events .register (' post_execute' , flush_figures )
180
+ if backend in (" inline" , " module://matplotlib_inline.backend_inline" ):
181
+ shell .events .register (" post_execute" , flush_figures )
181
182
182
183
# Save rcParams that will be overwrittern
183
184
shell ._saved_rcParams = {}
@@ -188,10 +189,10 @@ def configure_inline_support(shell, backend):
188
189
new_backend_name = "inline"
189
190
else :
190
191
try :
191
- shell .events .unregister (' post_execute' , flush_figures )
192
+ shell .events .unregister (" post_execute" , flush_figures )
192
193
except ValueError :
193
194
pass
194
- if hasattr (shell , ' _saved_rcParams' ):
195
+ if hasattr (shell , " _saved_rcParams" ):
195
196
matplotlib .rcParams .update (shell ._saved_rcParams )
196
197
del shell ._saved_rcParams
197
198
new_backend_name = "other"
@@ -209,10 +210,12 @@ def configure_inline_support(shell, backend):
209
210
def _enable_matplotlib_integration ():
210
211
"""Enable extra IPython matplotlib integration when we are loaded as the matplotlib backend."""
211
212
from matplotlib import get_backend
213
+
212
214
ip = get_ipython ()
213
215
backend = get_backend ()
214
- if ip and backend in (' inline' , ' module://matplotlib_inline.backend_inline' ):
216
+ if ip and backend in (" inline" , " module://matplotlib_inline.backend_inline" ):
215
217
from IPython .core .pylabtools import activate_matplotlib
218
+
216
219
try :
217
220
activate_matplotlib (backend )
218
221
configure_inline_support (ip , backend )
@@ -221,8 +224,9 @@ def _enable_matplotlib_integration():
221
224
def configure_once (* args ):
222
225
activate_matplotlib (backend )
223
226
configure_inline_support (ip , backend )
224
- ip .events .unregister ('post_run_cell' , configure_once )
225
- ip .events .register ('post_run_cell' , configure_once )
227
+ ip .events .unregister ("post_run_cell" , configure_once )
228
+
229
+ ip .events .register ("post_run_cell" , configure_once )
226
230
227
231
228
232
_enable_matplotlib_integration ()
@@ -233,13 +237,17 @@ def _fetch_figure_metadata(fig):
233
237
# determine if a background is needed for legibility
234
238
if _is_transparent (fig .get_facecolor ()):
235
239
# the background is transparent
236
- ticksLight = _is_light ([label .get_color ()
237
- for axes in fig .axes
238
- for axis in (axes .xaxis , axes .yaxis )
239
- for label in axis .get_ticklabels ()])
240
+ ticksLight = _is_light (
241
+ [
242
+ label .get_color ()
243
+ for axes in fig .axes
244
+ for axis in (axes .xaxis , axes .yaxis )
245
+ for label in axis .get_ticklabels ()
246
+ ]
247
+ )
240
248
if ticksLight .size and (ticksLight == ticksLight [0 ]).all ():
241
249
# there are one or more tick labels, all with the same lightness
242
- return {' needs_background' : ' dark' if ticksLight [0 ] else ' light' }
250
+ return {" needs_background" : " dark" if ticksLight [0 ] else " light" }
243
251
244
252
return None
245
253
@@ -249,13 +257,13 @@ def _is_light(color):
249
257
opposed to dark). Based on ITU BT.601 luminance formula (see
250
258
https://stackoverflow.com/a/596241)."""
251
259
rgbaArr = colors .to_rgba_array (color )
252
- return rgbaArr [:, :3 ].dot ((.299 , .587 , .114 )) > .5
260
+ return rgbaArr [:, :3 ].dot ((0 .299 , 0 .587 , 0 .114 )) > 0 .5
253
261
254
262
255
263
def _is_transparent (color ):
256
264
"""Determine transparency from alpha."""
257
265
rgba = colors .to_rgba (color )
258
- return rgba [3 ] < .5
266
+ return rgba [3 ] < 0 .5
259
267
260
268
261
269
def set_matplotlib_formats (* formats , ** kwargs ):
0 commit comments