code: def test_mosaic(close_figures):
      # make the same analysis on a known dataset
  
      # load the data and clean it a bit
      affairs = datasets.fair.load_pandas()
      datas = affairs.exog
      # any time greater than 0 is cheating
      datas["cheated"] = affairs.endog > 0
      # sort by the marriage quality and give meaningful name
      # [rate_marriage, age, yrs_married, children,
      # religious, educ, occupation, occupation_husb]
      datas = datas.sort_values(["rate_marriage", "religious"])
  
      num_to_desc = {
          1: "awful",
          2: "bad",
          3: "intermediate",
          4: "good",
          5: "wonderful",
      }
      datas["rate_marriage"] = datas["rate_marriage"].map(num_to_desc)
      num_to_faith = {
          1: "non religious",
          2: "poorly religious",
          3: "religious",
          4: "very religious",
      }
      datas["religious"] = datas["religious"].map(num_to_faith)
      num_to_cheat = {False: "faithful", True: "cheated"}
      datas["cheated"] = datas["cheated"].map(num_to_cheat)
      # finished cleaning
      _, ax = plt.subplots(2, 2)
      mosaic(
          datas,
          ["rate_marriage", "cheated"],
          ax=ax[0, 0],
          title="by marriage happiness",
      )
      mosaic(
          datas,
          ["religious", "cheated"],
          ax=ax[0, 1],
          title="by religiosity",
      )
      mosaic(
          datas,
          ["rate_marriage", "religious", "cheated"],
          ax=ax[1, 0],
          title="by both",
          labelizer=lambda k: "",
      )
      ax[1, 0].set_xlabel("marriage rating")
      ax[1, 0].set_ylabel("religion status")
      mosaic(
          datas,
          ["religious", "rate_marriage"],
          ax=ax[1, 1],
          title="inter-dependence",
          axes_label=False,
      )
      plt.suptitle("extramarital affairs (plot 3 of 4)")
  
imports: from statsmodels.compat.python import lrange
  from io import BytesIO
  from itertools import product
  import numpy
  from numpy.testing import assert_, assert_raises
  import pandas
  import pytest
  from statsmodels.api import datasets
  from statsmodels.graphics.mosaicplot import _hierarchical_split, _key_splitting, _normalize_split, _reduce_dict, _split_rect, mosaic
label_desc: Use image node_id 3 for calling a global function with example usage: test_mosaic(close_figures) without return types