def cleanup(style=None):
 def make_cleanup(func):
  if inspect.isgeneratorfunction(func):
   @functools.wraps(func)
   def wrapped_callable(*args, **kwargs):
    original_units_registry = matplotlib.units.registry.copy()
    original_settings = mpl.rcParams.copy()
    matplotlib.style.use(style)
    try:
     for yielded in func(*args, **kwargs):
      (yield yielded)
    finally:
     _do_cleanup(original_units_registry, original_settings)
  else:
   @functools.wraps(func)
   def wrapped_callable(*args, **kwargs):
    original_units_registry = matplotlib.units.registry.copy()
    original_settings = mpl.rcParams.copy()
    matplotlib.style.use(style)
    try:
     func(*args, **kwargs)
    finally:
     _do_cleanup(original_units_registry, original_settings)
  return wrapped_callable
 if isinstance(style, six.string_types):
  return make_cleanup
 else:
  result = make_cleanup(style)
  style = u'classic'
  return result

def cleanup ( style = None ) : def make_cleanup ( func ) : if inspect . isgeneratorfunction ( func ) : @ functools . wraps ( func ) def wrapped_callable ( * args , ** kwargs ) : original_units_registry = matplotlib . units . registry . copy ( ) original_settings = mpl . rcParams . copy ( ) matplotlib . style . use ( style ) try : for yielded in func ( * args , ** kwargs ) : ( yield yielded ) finally : _do_cleanup ( original_units_registry , original_settings ) else : @ functools . wraps ( func ) def wrapped_callable ( * args , ** kwargs ) : original_units_registry = matplotlib . units . registry . copy ( ) original_settings = mpl . rcParams . copy ( ) matplotlib . style . use ( style ) try : func ( * args , ** kwargs ) finally : _do_cleanup ( original_units_registry , original_settings ) return wrapped_callable if isinstance ( style , six . string_types ) : return make_cleanup else : result = make_cleanup ( style ) style = u'classic' return result
cleanup output .