@@ -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"
@@ -211,13 +212,15 @@ def _enable_matplotlib_integration():
211
212
ip = get_ipython ()
212
213
213
214
import matplotlib
215
+
214
216
if matplotlib .__version_info__ >= (3 , 10 ):
215
217
backend = matplotlib .get_backend (auto_select = False )
216
218
else :
217
219
backend = matplotlib .rcParams ._get ("backend" )
218
220
219
- if ip and backend in (' inline' , ' module://matplotlib_inline.backend_inline' ):
221
+ if ip and backend in (" inline" , " module://matplotlib_inline.backend_inline" ):
220
222
from IPython .core .pylabtools import activate_matplotlib
223
+
221
224
try :
222
225
activate_matplotlib (backend )
223
226
configure_inline_support (ip , backend )
@@ -226,8 +229,9 @@ def _enable_matplotlib_integration():
226
229
def configure_once (* args ):
227
230
activate_matplotlib (backend )
228
231
configure_inline_support (ip , backend )
229
- ip .events .unregister ('post_run_cell' , configure_once )
230
- ip .events .register ('post_run_cell' , configure_once )
232
+ ip .events .unregister ("post_run_cell" , configure_once )
233
+
234
+ ip .events .register ("post_run_cell" , configure_once )
231
235
232
236
233
237
_enable_matplotlib_integration ()
@@ -238,13 +242,17 @@ def _fetch_figure_metadata(fig):
238
242
# determine if a background is needed for legibility
239
243
if _is_transparent (fig .get_facecolor ()):
240
244
# the background is transparent
241
- ticksLight = _is_light ([label .get_color ()
242
- for axes in fig .axes
243
- for axis in (axes .xaxis , axes .yaxis )
244
- for label in axis .get_ticklabels ()])
245
+ ticksLight = _is_light (
246
+ [
247
+ label .get_color ()
248
+ for axes in fig .axes
249
+ for axis in (axes .xaxis , axes .yaxis )
250
+ for label in axis .get_ticklabels ()
251
+ ]
252
+ )
245
253
if ticksLight .size and (ticksLight == ticksLight [0 ]).all ():
246
254
# there are one or more tick labels, all with the same lightness
247
- return {' needs_background' : ' dark' if ticksLight [0 ] else ' light' }
255
+ return {" needs_background" : " dark" if ticksLight [0 ] else " light" }
248
256
249
257
return None
250
258
@@ -254,13 +262,13 @@ def _is_light(color):
254
262
opposed to dark). Based on ITU BT.601 luminance formula (see
255
263
https://stackoverflow.com/a/596241)."""
256
264
rgbaArr = colors .to_rgba_array (color )
257
- return rgbaArr [:, :3 ].dot ((.299 , .587 , .114 )) > .5
265
+ return rgbaArr [:, :3 ].dot ((0 .299 , 0 .587 , 0 .114 )) > 0 .5
258
266
259
267
260
268
def _is_transparent (color ):
261
269
"""Determine transparency from alpha."""
262
270
rgba = colors .to_rgba (color )
263
- return rgba [3 ] < .5
271
+ return rgba [3 ] < 0 .5
264
272
265
273
266
274
def set_matplotlib_formats (* formats , ** kwargs ):
0 commit comments