miscplot_1.py 754 B

123456789101112131415161718192021222324
  1. def palplot(pal, size=1):
  2. """Plot the values in a color palette as a horizontal array.
  3. Parameters
  4. ----------
  5. pal : sequence of matplotlib colors
  6. colors, i.e. as returned by seaborn.color_palette()
  7. size :
  8. scaling factor for size of plot
  9. """
  10. n = len(pal)
  11. f, ax = plt.subplots(1, 1, figsize=(n * size, size))
  12. ax.imshow(np.arange(n).reshape(1, n),
  13. cmap=mpl.colors.ListedColormap(list(pal)),
  14. interpolation="nearest", aspect="auto")
  15. ax.set_xticks(np.arange(n) - .5)
  16. ax.set_yticks([-.5, .5])
  17. # Ensure nice border between colors
  18. ax.set_xticklabels(["" for _ in range(n)])
  19. # The proper way to set no ticks
  20. ax.yaxis.set_major_locator(ticker.NullLocator())