code: def plot_histogram(
      result, dimension_identifier, bins=20, rotate_labels=0, ax=None
  ):
      """
      Create and return a Matplotlib figure with a histogram
      of the samples from the optimization results,
      for a given dimension of the search-space.
  
      Parameters
      ----------
      result : `OptimizeResult`
          The optimization results e.g. from calling `gp_minimize()`.
  
      dimension_identifier : str or int
          Name or index of a dimension in the search-space.
  
      bins : int, bins=20
          Number of bins in the histogram.
  
      rotate_labels : int, rotate_labels=0
          Degree to rotate category-names on the x-axis.
          Only used for Categorical dimensions.
  
      Returns
      -------
      ax : `Matplotlib.Axes`
          The Matplotlib Axes-object.
      """
  
      # Get the search-space instance from the optimization results.
      space = result.space
  
      # Get the dimension-object.
      index, dimension = space[dimension_identifier]
  
      # Get the samples from the optimization-log for that particular dimension.
      samples = [x[index] for x in result.x_iters]
  
      if ax is None:
          ax = plt.gca()
  
      if isinstance(dimension, Categorical):
          # When the search-space dimension is Categorical, it means
          # that the possible values are strings. Matplotlib's histogram
          # does not support this, so we have to make a bar-plot instead.
  
          # NOTE: This only shows the categories that are in the samples.
          # So if a category was not sampled, it will not be shown here.
  
          # Count the number of occurrences of the string-categories.
          counter = Counter(samples)
  
          # The counter returns a dict where the keys are the category-names
          # and the values are the number of occurrences for each category.
          names = list(counter.keys())
          counts = list(counter.values())
  
          # Although Matplotlib's docs indicate that the bar() function
          # can take a list of strings for the x-axis, it doesn't appear to work.
          # So we hack it by creating a list of integers and setting the
          # tick-labels with the category-names instead.
          x = np.arange(len(counts))
  
          # Plot using bars.
          ax.bar(x, counts, tick_label=names)
  
          # Adjust the rotation of the category-names on the x-axis.
          ax.set_xticklabels(labels=names, rotation=rotate_labels)
      else:
          # Otherwise the search-space Dimension is either integer or float,
          # in which case the histogram can be plotted more easily.
          if dimension.prior == "log-uniform":
              # Map the number of bins to a log-space for the dimension bounds.
              bins_mapped = np.logspace(
                  *np.log10(dimension.bounds), bins
              )
          else:
              # Use the original number of bins.
              bins_mapped = bins
          # Plot the histogram.
          ax.hist(samples, bins=bins_mapped, range=dimension.bounds)
  
          # Use log-scale on the x-axis?
          if dimension.prior == "log-uniform":
              ax.set_xscale("log")
  
      # Set the labels.
      ax.set_xlabel(dimension.name)
      ax.set_ylabel("Sample Count")
  
      return ax
  
imports: import sys
  import numpy
  from itertools import count
  from functools import partial
  from scipy.optimize import OptimizeResult
  from .acquisition import _gaussian_acquisition
  from skopt import expected_minimum, expected_minimum_random_sampling
  from .space import Categorical
  from collections import Counter
  import matplotlib.pyplot
  from matplotlib.pyplot import cm
  from matplotlib.ticker import LogLocator
  from matplotlib.ticker import MaxNLocator, FuncFormatter
label_desc: Use image node_id 12 for calling a global function with example usage: plot_histogram(result, dimension_identifier, bins, rotate_labels, ax) and returns: ax