n = len(pal)
f, ax = plt.subplots(1, 1, figsize=(n * size, size))
ax.imshow(np.arange(n).reshape(1, n), cmap=mpl.colors.ListedColormap(list(
    pal)), interpolation='nearest', aspect='auto')
ax.set_xticks(np.arange(n) - 0.5)
ax.set_yticks([-0.5, 0.5])
ax.set_xticklabels([])
ax.set_yticklabels([])
Displaying matrix-like image with RGB-colored cells in matplotlib