text: import matplotlib.pyplot as plt
  import numpy as np
  from matplotlib import colors as mcolors
  
  def show_color_swatches():
      colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
  
      # Sort colors by hue, saturation, value and name.
      by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
                  for name, color in colors.items())
      sorted_names = [name for hsv, name in by_hsv]
  
      n = len(sorted_names)
      ncols = 4
      nrows = n // ncols + 1
  
      fig, ax = plt.subplots(figsize=(12, 8))
  
      # Get height and width
      X, Y = fig.get_dpi() * fig.get_size_inches()
      h = Y / (nrows + 1)
      w = X / ncols
  
      for i, name in enumerate(sorted_names):
          col = i % ncols
          row = i // ncols
          y = Y - (row * h) - h
  
          xi_line = w * (col + 0.05)
          xf_line = w * (col + 0.25)
          xi_text = w * (col + 0.3)
  
          ax.text(xi_text, y, name, fontsize=(h * 0.8),
              horizontalalignment='left',
              verticalalignment='center')
  
          ax.hlines(y + h * 0.1, xi_line, xf_line,
                color=colors[name], linewidth=(h * 0.6))
  
      ax.set_xlim(0, X)
      ax.set_ylim(0, Y)
      ax.set_axis_off()
  
      fig.subplots_adjust(left=0, right=1,
                      top=1, bottom=0,
                      hspace=0, wspace=0)
      
      plt.show()
      
  def prop_cycle_colors():
      prop_cycle = plt.rcParams['axes.prop_cycle']
      colors = prop_cycle.by_key()['color']
  
      lwbase = plt.rcParams['lines.linewidth']
      thin = lwbase / 2
      thick = lwbase * 3
  
      fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(12, 8), sharex=True, sharey=True)
      for icol in range(2):
          if icol == 0:
              lwx, lwy = thin, lwbase
          else:
              lwx, lwy = lwbase, thick
          for irow in range(2):
              for i, color in enumerate(colors):
                  axs[irow, icol].axhline(i, color=color, lw=lwx)
                  axs[irow, icol].axvline(i, color=color, lw=lwy)
  
          axs[1, icol].set_facecolor('k')
          axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2))
          axs[0, icol].set_title('line widths (pts): %g, %g' % (lwx, lwy),
                                 fontsize='medium')
  
      for irow in range(2):
          axs[irow, 0].yaxis.set_ticks(np.arange(0, 10, 2))
  
      fig.suptitle('Colors in the default prop_cycle', fontsize='large')
  
      plt.show()
  
  def show_colormaps():
      cmaps = [('Perceptually Uniform Sequential', [
                  'viridis', 'plasma', 'inferno', 'magma', 'cividis']),
               ('Sequential', [
                  'Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',
                  'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                  'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']),
               ('Sequential (2)', [
                  'binary', 'gist_yarg', 'gist_gray', 'gray', 'bone', 'pink',
                  'spring', 'summer', 'autumn', 'winter', 'cool', 'Wistia',
                  'hot', 'afmhot', 'gist_heat', 'copper']),
               ('Diverging', [
                  'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
                  'RdYlBu', 'RdYlGn', 'Spectral', 'coolwarm', 'bwr', 'seismic']),
               ('Qualitative', [
                  'Pastel1', 'Pastel2', 'Paired', 'Accent',
                  'Dark2', 'Set1', 'Set2', 'Set3',
                  'tab10', 'tab20', 'tab20b', 'tab20c']),
               ('Miscellaneous', [
                  'flag', 'prism', 'ocean', 'gist_earth', 'terrain', 'gist_stern',
                  'gnuplot', 'gnuplot2', 'CMRmap', 'cubehelix', 'brg', 'hsv',
                  'gist_rainbow', 'rainbow', 'jet', 'nipy_spectral', 'gist_ncar'])]
  
  
  
      nrows = max(len(cmap_list) for cmap_category, cmap_list in cmaps)
      gradient = np.linspace(0, 1, 256)
      gradient = np.vstack((gradient, gradient))
  
  
      def plot_color_gradients(cmap_category, cmap_list, nrows):
          fig, axes = plt.subplots(nrows=nrows)
          fig.subplots_adjust(top=0.95, bottom=0.01, left=0.2, right=0.99)
          axes[0].set_title(cmap_category + ' colormaps', fontsize=14)
  
          for ax, name in zip(axes, cmap_list):
              ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
              pos = list(ax.get_position().bounds)
              x_text = pos[0] - 0.01
              y_text = pos[1] + pos[3]/2.
              fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
  
          # Turn off *all* ticks & spines, not just the ones with colormaps.
          for ax in axes:
              ax.set_axis_off()
  
  
      for cmap_category, cmap_list in cmaps:
          plot_color_gradients(cmap_category, cmap_list, nrows)
  
      plt.show()