-
-
Save kvalv/fd844f35d03898d67851e3a970b49f75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import seaborn | |
| import graphics | |
| def color_palette(n_colors): | |
| ''' | |
| returns a list of rgb-colors | |
| ''' | |
| palettes = [seaborn.color_palette(each, 10) for each in | |
| 'cubehelix Set2 husl'.split()] | |
| L = [] | |
| for pal in palettes: | |
| for each in pal: | |
| L.append([int(round(e*255)) for e in each]) | |
| if n_colors > len(L): | |
| L = (1+(n_colors // L)) * L | |
| c_vals = L[:n_colors] | |
| cmap = {job: graphics.color_rgb(*col) for job, col in zip(range(n_colors), c_vals)} | |
| return cmap | |
| # maximally supported n_colors currently is 30 | |
| # but looking at the implementation of color_palette function, | |
| # it should be obvious how to make more | |
| n_colors = 25 # for example | |
| width, height = 500, 100 | |
| win = graphics.GraphWin('hitler did nothing wrong', width, height) | |
| cmap = color_palette(n_colors=n_colors) | |
| dx, dy = width / n_colors, height / 2 | |
| for t in range(n_colors): | |
| p0 = graphics.Point(t*dx, 0) | |
| p1 = graphics.Point((t+1)*dx, 100) | |
| rect = graphics.Rectangle(p0, p1) | |
| rect.setFill(cmap[t]) | |
| rect.draw(win) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment