@@ -43,10 +43,11 @@ def new_figure_manager_given_figure(num, figure):
4343 # https://github.com/ipython/ipython/issues/1612
4444 # https://github.com/matplotlib/matplotlib/issues/835
4545
46- if not hasattr (figure , ' show' ):
46+ if not hasattr (figure , " show" ):
4747 # Queue up `figure` for display
4848 figure .show = lambda * a : display (
49- figure , metadata = _fetch_figure_metadata (figure ))
49+ figure , metadata = _fetch_figure_metadata (figure )
50+ )
5051
5152 # If matplotlib was manually set to non-interactive mode, this function
5253 # should be a no-op (otherwise we'll generate duplicate plots, since a user
@@ -89,14 +90,14 @@ def show(close=None, block=None):
8990 for figure_manager in Gcf .get_all_fig_managers ():
9091 display (
9192 figure_manager .canvas .figure ,
92- metadata = _fetch_figure_metadata (figure_manager .canvas .figure )
93+ metadata = _fetch_figure_metadata (figure_manager .canvas .figure ),
9394 )
9495 finally :
9596 show ._to_draw = []
9697 # only call close('all') if any to close
9798 # close triggers gc.collect, which can be slow
9899 if close and Gcf .get_all_fig_managers ():
99- matplotlib .pyplot .close (' all' )
100+ matplotlib .pyplot .close (" all" )
100101
101102
102103# This flag will be reset by draw_if_interactive when called
@@ -176,8 +177,8 @@ def configure_inline_support(shell, backend):
176177 if cfg not in shell .configurables :
177178 shell .configurables .append (cfg )
178179
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 )
181182
182183 # Save rcParams that will be overwrittern
183184 shell ._saved_rcParams = {}
@@ -188,10 +189,10 @@ def configure_inline_support(shell, backend):
188189 new_backend_name = "inline"
189190 else :
190191 try :
191- shell .events .unregister (' post_execute' , flush_figures )
192+ shell .events .unregister (" post_execute" , flush_figures )
192193 except ValueError :
193194 pass
194- if hasattr (shell , ' _saved_rcParams' ):
195+ if hasattr (shell , " _saved_rcParams" ):
195196 matplotlib .rcParams .update (shell ._saved_rcParams )
196197 del shell ._saved_rcParams
197198 new_backend_name = "other"
@@ -211,13 +212,15 @@ def _enable_matplotlib_integration():
211212 ip = get_ipython ()
212213
213214 import matplotlib
215+
214216 if matplotlib .__version_info__ >= (3 , 10 ):
215217 backend = matplotlib .get_backend (auto_select = False )
216218 else :
217219 backend = matplotlib .rcParams ._get ("backend" )
218220
219- if ip and backend in (' inline' , ' module://matplotlib_inline.backend_inline' ):
221+ if ip and backend in (" inline" , " module://matplotlib_inline.backend_inline" ):
220222 from IPython .core .pylabtools import activate_matplotlib
223+
221224 try :
222225 activate_matplotlib (backend )
223226 configure_inline_support (ip , backend )
@@ -226,8 +229,9 @@ def _enable_matplotlib_integration():
226229 def configure_once (* args ):
227230 activate_matplotlib (backend )
228231 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 )
231235
232236
233237_enable_matplotlib_integration ()
@@ -238,13 +242,17 @@ def _fetch_figure_metadata(fig):
238242 # determine if a background is needed for legibility
239243 if _is_transparent (fig .get_facecolor ()):
240244 # 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+ )
245253 if ticksLight .size and (ticksLight == ticksLight [0 ]).all ():
246254 # 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" }
248256
249257 return None
250258
@@ -254,13 +262,13 @@ def _is_light(color):
254262 opposed to dark). Based on ITU BT.601 luminance formula (see
255263 https://stackoverflow.com/a/596241)."""
256264 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
258266
259267
260268def _is_transparent (color ):
261269 """Determine transparency from alpha."""
262270 rgba = colors .to_rgba (color )
263- return rgba [3 ] < .5
271+ return rgba [3 ] < 0 .5
264272
265273
266274def set_matplotlib_formats (* formats , ** kwargs ):
0 commit comments