class_docstr: Store a set of contour lines or filled regions.
  
  User-callable method: `~.Axes.clabel`
  
  Parameters
  ----------
  ax : `~matplotlib.axes.Axes`
  
  levels : [level0, level1, ..., leveln]
      A list of floating point numbers indicating the contour levels.
  
  allsegs : [level0segs, level1segs, ...]
      List of all the polygon segments for all the *levels*.
      For contour lines ``len(allsegs) == len(levels)``, and for
      filled contour regions ``len(allsegs) = len(levels)-1``. The lists
      should look like ::
  
          level0segs = [polygon0, polygon1, ...]
          polygon0 = [[x0, y0], [x1, y1], ...]
  
  allkinds : ``None`` or [level0kinds, level1kinds, ...]
      Optional list of all the polygon vertex kinds (code types), as
      described and used in Path. This is used to allow multiply-
      connected paths such as holes within filled polygons.
      If not ``None``, ``len(allkinds) == len(allsegs)``. The lists
      should look like ::
  
          level0kinds = [polygon0kinds, ...]
          polygon0kinds = [vertexcode0, vertexcode1, ...]
  
      If *allkinds* is not ``None``, usually all polygons for a
      particular contour level are grouped together so that
      ``level0segs = [polygon0]`` and ``level0kinds = [polygon0kinds]``.
  
  **kwargs
      Keyword arguments are as described in the docstring of
      `~.Axes.contour`.
  
  %(contour_set_attributes)s
class_docstr_tok: ["Store","a","set","of","contour","lines","or","filled","regions",".","User-callable","method",":","`","~.Axes.clabel","`","Parameters","--","--","--","--","--","ax",":","`","~matplotlib.axes.Axes","`","levels",":","[","level0",",","level1",",","...",",","leveln","]","A","list","of","floating","point","numbers","indicating","the","contour","levels",".","allsegs",":","[","level0segs",",","level1segs",",","...","]","List","of","all","the","polygon","segments","for","all","the","*","levels","*",".","For","contour","lines","``","len","(","allsegs",")","==","len","(","levels",")","``",",","and","for","filled","contour","regions","``","len","(","allsegs",")","=","len","(","levels",")","-1","``",".","The","lists","should","look","like",":",":","level0segs","=","[","polygon0",",","polygon1",",","...","]","polygon0","=","[","[","x0",",","y0","]",",","[","x1",",","y1","]",",","...","]","allkinds",":","``","None","``","or","[","level0kinds",",","level1kinds",",","...","]","Optional","list","of","all","the","polygon","vertex","kinds","(","code","types",")",",","as","described","and","used","in","Path",".","This","is","used","to","allow","multiply-","connected","paths","such","as","holes","within","filled","polygons",".","If","not","``","None","``",",","``","len","(","allkinds",")","==","len","(","allsegs",")","``",".","The","lists","should","look","like",":",":","level0kinds","=","[","polygon0kinds",",","...","]","polygon0kinds","=","[","vertexcode0",",","vertexcode1",",","...","]","If","*","allkinds","*","is","not","``","None","``",",","usually","all","polygons","for","a","particular","contour","level","are","grouped","together","so","that","``","level0segs","=","[","polygon0","]","``","and","``","level0kinds","=","[","polygon0kinds","]","``",".","*","*","kwargs","Keyword","arguments","are","as","described","in","the","docstring","of","`","~.Axes.contour","`",".","%","(","contour_set_attributes",")","s"]
docstr: Return a list of artists and labels suitable for passing through
  to `~.Axes.legend` which represent this ContourSet.
  
  The labels have the form "0 < x <= 1" stating the data ranges which
  the artists represent.
  
  Parameters
  ----------
  variable_name : str
      The string used inside the inequality used on the labels.
  str_format : function: float -> str
      Function used to format the numbers in the labels.
  
  Returns
  -------
  artists : list[`.Artist`]
      A list of the artists.
  labels : list[str]
      A list of the labels.
docstr_tok: ["Return","a","list","of","artists","and","labels","suitable","for","passing","through","to","`","~.Axes.legend","`","which","represent","this","ContourSet",".","The","labels","have","the","form","``","0","<","x","<","=","1","''","stating","the","data","ranges","which","the","artists","represent",".","Parameters","--","--","--","--","--","variable_name",":","str","The","string","used","inside","the","inequality","used","on","the","labels",".","str_format",":","function",":","float","-",">","str","Function","used","to","format","the","numbers","in","the","labels",".","Returns","--","--","--","-","artists",":","list","[","`",".Artist","`","]","A","list","of","the","artists",".","labels",":","list","[","str","]","A","list","of","the","labels","."]
code: def legend_elements(self, variable_name="x", str_format=str):
      """
      Return a list of artists and labels suitable for passing through
      to `~.Axes.legend` which represent this ContourSet.
  
      The labels have the form "0 < x <= 1" stating the data ranges which
      the artists represent.
  
      Parameters
      ----------
      variable_name : str
          The string used inside the inequality used on the labels.
      str_format : function: float -> str
          Function used to format the numbers in the labels.
  
      Returns
      -------
      artists : list[`.Artist`]
          A list of the artists.
      labels : list[str]
          A list of the labels.
      """
      artists = []
      labels = []
  
      if self.filled:
          lowers, uppers = self._get_lowers_and_uppers()
          n_levels = len(self._paths)
          for idx in range(n_levels):
              artists.append(
                  mpatches.Rectangle(
                      (0, 0),
                      1,
                      1,
                      facecolor=self.get_facecolor()[idx],
                      hatch=self.hatches[idx % len(self.hatches)],
                  )
              )
              lower = str_format(lowers[idx])
              upper = str_format(uppers[idx])
              if idx == 0 and self.extend in ("min", "both"):
                  labels.append(rf"${variable_name} \leq {lower}s$")
              elif idx == n_levels - 1 and self.extend in (
                  "max",
                  "both",
              ):
                  labels.append(rf"${variable_name} > {upper}s$")
              else:
                  labels.append(
                      rf"${lower} < {variable_name} \leq {upper}$"
                  )
      else:
          for idx, level in enumerate(self.levels):
              artists.append(
                  Line2D(
                      [],
                      [],
                      color=self.get_edgecolor()[idx],
                      linewidth=self.get_linewidths()[idx],
                      linestyle=self.get_linestyles()[idx],
                  )
              )
              labels.append(rf"${variable_name} = {str_format(level)}$")
  
      return artists, labels
  
imports: from contextlib import ExitStack
  import functools
  import math
  from numbers import Integral
  import numpy
  from numpy import ma
  import matplotlib
  from matplotlib import _api, _docstring
  from matplotlib.backend_bases import MouseButton
  from matplotlib.lines import Line2D
  from matplotlib.path import Path
  from matplotlib.text import Text
  import matplotlib.ticker
  import matplotlib.cm
  import matplotlib.colors
  import matplotlib.collections
  import matplotlib.font_manager
  import matplotlib.cbook
  import matplotlib.patches
  import matplotlib.transforms
label_desc: Use image node_id 7 for calling the ContourSet obj's underlying member method code with example usage: obj.legend_elements(variable_name, str_format) and returns: artists,  labels