class_docstr: This object provides the primary interface to the functionality of this library. You can think of it as
  an adaptor that adapts the various decision-tree based libraries for use with dtreeviz. In implementation,
  however, this object encapsulates the key functionality and API but delegates tree model adaptation
  from sklearn etc... to dtreeviz.models.ShadowDecTree subclasses.
class_docstr_tok: ["This","object","provides","the","primary","interface","to","the","functionality","of","this","library",".","You","can","think","of","it","as","an","adaptor","that","adapts","the","various","decision-tree","based","libraries","for","use","with","dtreeviz",".","In","implementation",",","however",",","this","object","encapsulates","the","key","functionality","and","API","but","delegates","tree","model","adaptation","from","sklearn","etc","...","to","dtreeviz.models.ShadowDecTree","subclasses","."]
docstr: Visualize leaf sizes.
  
  Interpreting leaf sizes can help us to see how the data is spread over the tree:
  - if we have a leaf with many samples and a good purity, it means that we can be pretty confident
  on its prediction.
  - if we have a leaf with few samples and a good purity, we cannot be very confident on its prediction and
  it could be a sign of overfitting.
  - by visualizing leaf sizes, we can easily discover important leaves . Using node_stats() function we
  can take all of its samples and discover common patterns between leaf samples.
  - if the tree contains a lot of leaves and we want a general overview about leaves sizes, we can use the
  parameter display_type='hist' to display the histogram of leaf sizes.
  
  There is the option to filter the leaves with sizes between 'min_size' and 'max_size'. This is helpful
  especially when you want to investigate leaves with sizes from a specific range.
  
  This method contains three types of visualizations:
  - If display_type = 'plot' it will show leaf sizes using a plot.
  - If display_type = 'text' it will show leaf sizes as plain text. This method is preferred if number
  of leaves is very large and the plot become very big and hard to interpret.
  - If display_type = 'hist' it will show leaf size histogram. Useful when you want to easily see the general
  distribution of leaf sizes.
  
  Usage example :
  viz_model = dtreeviz.model(tree_model, X_train=dataset[features], y_train=dataset[target],
                             feature_names=features, target_name=target, class_names=[0, 1])
  viz_model.leaf_sizes()
  
  :param display_type: str, optional
     'plot', 'text'. 'hist'
  :param colors: dict
      The set of colors used for plotting
  :param fontsize: int
      Plot labels font size
  :param fontname: str
      Plot labels font name
  :param grid: bool
      True if we want to display the grid lines on the visualization
  :param bins: int
      Number of histogram bins
  :param min_size: int
      Min size for a leaf
  :param max_size: int
      Max size for a leaf
  :param figsize: optional (width, height) in inches for the entire plot
      :param ax: optional matplotlib "axes" to draw into
code: def leaf_sizes(
      self,
      display_type: str = "plot",
      colors: dict = None,
      fontsize: int = 10,
      fontname: str = "Arial",
      grid: bool = False,
      bins: int = 10,
      min_size: int = 0,
      max_size: int = None,
      figsize: tuple = None,
      ax=None,
  ):
      """Visualize leaf sizes.
  
      Interpreting leaf sizes can help us to see how the data is spread over the tree:
      - if we have a leaf with many samples and a good purity, it means that we can be pretty confident
      on its prediction.
      - if we have a leaf with few samples and a good purity, we cannot be very confident on its prediction and
      it could be a sign of overfitting.
      - by visualizing leaf sizes, we can easily discover important leaves . Using node_stats() function we
      can take all of its samples and discover common patterns between leaf samples.
      - if the tree contains a lot of leaves and we want a general overview about leaves sizes, we can use the
      parameter display_type='hist' to display the histogram of leaf sizes.
  
      There is the option to filter the leaves with sizes between 'min_size' and 'max_size'. This is helpful
      especially when you want to investigate leaves with sizes from a specific range.
  
      This method contains three types of visualizations:
      - If display_type = 'plot' it will show leaf sizes using a plot.
      - If display_type = 'text' it will show leaf sizes as plain text. This method is preferred if number
      of leaves is very large and the plot become very big and hard to interpret.
      - If display_type = 'hist' it will show leaf size histogram. Useful when you want to easily see the general
      distribution of leaf sizes.
  
      Usage example :
      viz_model = dtreeviz.model(tree_model, X_train=dataset[features], y_train=dataset[target],
                                 feature_names=features, target_name=target, class_names=[0, 1])
      viz_model.leaf_sizes()
  
      :param display_type: str, optional
         'plot', 'text'. 'hist'
      :param colors: dict
          The set of colors used for plotting
      :param fontsize: int
          Plot labels font size
      :param fontname: str
          Plot labels font name
      :param grid: bool
          True if we want to display the grid lines on the visualization
      :param bins: int
          Number of histogram bins
      :param min_size: int
          Min size for a leaf
      :param max_size: int
          Max size for a leaf
      :param figsize: optional (width, height) in inches for the entire plot
          :param ax: optional matplotlib "axes" to draw into
      """
      leaf_id, leaf_sizes = self.shadow_tree.get_leaf_sample_counts(
          min_size, max_size
      )
  
      if display_type == "text":
          for leaf, samples in zip(leaf_id, leaf_sizes):
              print(f"leaf {leaf} has {samples} samples")
      elif display_type in ["plot", "hist"]:
          colors = adjust_colors(colors)
          if ax is None:
              if figsize:
                  fig, ax = plt.subplots(figsize=figsize)
              else:
                  fig, ax = plt.subplots()
      else:
          raise ValueError(f"Unknown display_type = {display_type}")
  
      if display_type == "plot":
          ax.set_xticks(range(0, len(leaf_id)))
          ax.set_xticklabels(leaf_id)
          barcontainers = ax.bar(
              range(0, len(leaf_id)),
              leaf_sizes,
              color=colors["hist_bar"],
              lw=0.3,
              align="center",
              width=1,
          )
          for rect in barcontainers.patches:
              rect.set_linewidth(0.5)
              rect.set_edgecolor(colors["rect_edge"])
  
          _format_axes(
              ax,
              "Leaf IDs",
              "Samples Count",
              colors,
              fontsize,
              fontname,
              ticks_fontsize=None,
              grid=grid,
          )
  
      elif display_type == "hist":
          n, bins, patches = ax.hist(
              leaf_sizes, bins=bins, color=colors["hist_bar"]
          )
          for rect in patches:
              rect.set_linewidth(0.5)
              rect.set_edgecolor(colors["rect_edge"])
  
          _format_axes(
              ax,
              "Leaf Sample",
              "Leaf Count",
              colors,
              fontsize,
              fontname,
              ticks_fontsize=None,
              grid=grid,
          )
  
imports: import os
  import tempfile
  from typing import Mapping, List, Callable
  import matplotlib
  import matplotlib.patches
  import matplotlib.pyplot
  import numpy
  import pandas
  from colour import Color, rgb2hex
  from sklearn import tree
  from dtreeviz.colors import adjust_colors
  from dtreeviz.interpretation import explain_prediction_plain_english, explain_prediction_sklearn_default
  from dtreeviz.models.shadow_decision_tree import ShadowDecTree
  from dtreeviz.models.shadow_decision_tree import ShadowDecTreeNode
  from dtreeviz.utils import myround, DTreeVizRender, add_classifier_legend, _format_axes, _draw_wedge, _set_wedge_ticks, tessellate, is_numeric
label_desc: Use image node_id 2 for calling the DTreeVizAPI obj's underlying member method code with example usage: obj.leaf_sizes(display_type, colors, fontsize, fontname, grid, bins, min_size, max_size, figsize, ax) without return types