code: def test_move_legend_matplotlib_objects():
      fig, ax = plt.subplots()
  
      colors = "C2", "C5"
      labels = "first label", "second label"
      title = "the legend"
  
      for color, label in zip(colors, labels):
          ax.plot([0, 1], color=color, label=label)
      ax.legend(loc="upper right", title=title)
      utils._draw_figure(fig)
      xfm = ax.transAxes.inverted().transform
  
      # --- Test axes legend
  
      old_pos = xfm(ax.legend_.legendPatch.get_extents())
  
      new_fontsize = 14
      utils.move_legend(ax, "lower left", title_fontsize=new_fontsize)
      utils._draw_figure(fig)
      new_pos = xfm(ax.legend_.legendPatch.get_extents())
  
      assert (new_pos < old_pos).all()
      assert ax.legend_.get_title().get_text() == title
      assert ax.legend_.get_title().get_size() == new_fontsize
  
      # --- Test title replacement
  
      new_title = "new title"
      utils.move_legend(ax, "lower left", title=new_title)
      utils._draw_figure(fig)
      assert ax.legend_.get_title().get_text() == new_title
  
      # --- Test figure legend
  
      fig.legend(loc="upper right", title=title)
      _draw_figure(fig)
      xfm = fig.transFigure.inverted().transform
      old_pos = xfm(fig.legends[0].legendPatch.get_extents())
  
      utils.move_legend(fig, "lower left", title=new_title)
      _draw_figure(fig)
  
      new_pos = xfm(fig.legends[0].legendPatch.get_extents())
      assert (new_pos < old_pos).all()
      assert fig.legends[0].get_title().get_text() == new_title
  
imports: import re
  import tempfile
  from types import ModuleType
  from urllib.request import urlopen
  from http.client import HTTPException
  import numpy
  import pandas
  import matplotlib
  import matplotlib.pyplot
  from cycler import cycler
  import pytest
  from numpy.testing import assert_array_equal
  from pandas.testing import assert_series_equal, assert_frame_equal
  from seaborn import utils, rcmod, scatterplot
  from seaborn.utils import get_dataset_names, get_color_cycle, remove_na, load_dataset, _assign_default_kwargs, _check_argument, _draw_figure, _deprecate_ci, _version_predates, DATASET_NAMES_URL
  from seaborn._compat import get_legend_handles
label_desc: Use image node_id 9 for calling a global function with example usage: test_move_legend_matplotlib_objects() without return types