import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
# helper function to plot a
# color table
def colortable(colors, title,
colors_sort = True,
emptycols=0):
# cell dimensions
width = 212
height = 22
swatch_width = 48
margin = 12
topmargin = 40
# Sorting colors bbased on hue,
# saturation, value and name.
if colors_sort is True:
to_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))),
name)
for name, color in colors.items())
names = [name for hsv, name in to_hsv]
else:
names = list(colors)
length_of_names = len(names)
length_cols = 4 - emptycols
length_rows = length_of_names // length_cols + int(length_of_names % length_cols > 0)
width2 = widt