code: def draw_histogram(graph: Graph) -> Optional[Graph]:
      """Draw a histogram given the graph.
  
      Args:
        graph: The Graph object represents the necessary data to draw a histogram.
  
      Returns:
        A Graph object, or None if plotting raises TypeError given the raw data.
      """
      if not graph:
          return None
      try:
          # generate and open a new figure
          figure, ax = plt.subplots()
          # When graph.x or y is str, the histogram is ill-defined.
          ax.barh(graph.y, graph.x, color=graph.color)
          ax.set_title(graph.title)
          if graph.xlabel:
              ax.set_xlabel(graph.xlabel)
          if graph.ylabel:
              ax.set_ylabel(graph.ylabel)
          for index, value in enumerate(graph.x):
              show_value = (
                  f"{value:.2f}" if isinstance(value, float) else value
              )
              # To avoid the number has overlap with the box of the graph.
              if value > 0.9 * max(graph.x):
                  ax.text(
                      value - (value / 10),
                      index,
                      show_value,
                      va="center",
                      color="w",
                  )
              else:
                  ax.text(value, index, show_value, va="center")
  
          graph.figure = figure
          graph.base64str = figure_to_base64str(figure)
      except TypeError as e:
          logging.info(
              "skipping %s for histogram; plot error: %s:",
              graph.name,
              e,
          )
          return None
      finally:
          # closes the figure (to limit memory consumption)
          plt.close()
      return graph
  
file_path: model-card-toolkit/model_card_toolkit/utils/graphics.py
imports: import base64
  import io
  import logging
  from typing import Optional, Sequence, Tuple, Union
  import attr
  import matplotlib
  import matplotlib.pyplot
label_desc: Use image node_id 1 for calling a global function with example usage: draw_histogram(graph) and returns: graph, None, None