Added discrete rainbow styles proposed by Paul Tol#121
Added discrete rainbow styles proposed by Paul Tol#121echedey-ls merged 7 commits intogarrettj403:masterfrom
Conversation
echedey-ls
left a comment
There was a problem hiding this comment.
Thanks a lot @IchBinGROOT , this makes a great contribution to the project!
Two questions:
- How would you name the styles? Right now,
discrete-rainbow-*is a term that we both know from the author naming, have you considered any alternatives? - I'd like to test that the cyclers match Paul Tol's implementation. Do you recommend me any way to do so, maybe by sharing your generator script of the files?
I will leave this PR open for a few days so you can apply the changes whenever you want, and other people review as well.
Thanks for the contribution ❣️
| # from Paul Tot's website: https://personal.sron.nl/~pault/ | ||
|
|
||
| # Set color cycle | ||
| axes.prop_cycle : cycler('color', ['1965B0']) No newline at end of file |
There was a problem hiding this comment.
Can you add a new line at the end of the mplstyle files? Just to be style-consistent with the existing codebase.
There was a problem hiding this comment.
Of course I can add a new line, that is easily done in the generating script.
| v2.1.3 (05-Aug-2024) | ||
| ==================== | ||
| - Now all subdirectories of the ``styles`` folder are parsed for styles | ||
| - Added all 23 "discrete rainbow" styles proposed by Paul Tol on his website |
There was a problem hiding this comment.
Can you merge these entries to the v2.1.2 section? That will be the next release.
There was a problem hiding this comment.
I can certainly do so
|
Hey @IchBinGROOT , I saw there was no further activity in this PR so I continued your work. I found a typo in one of the colors btw. Anyways, thank you very much @IchBinGROOT ❣️ . I've left updating documentation and the example file for you or anybody else. When I get some more time I may be able to do so and release a new version. Until then help is pretty much appreciated 😉 Code - click to expand
from string import Template
from pathlib import Path
def __rainbow_discrete(lut=None):
"""
Define colormap 'rainbow_discrete'.
"""
clrs = ['#E8ECFB', '#D9CCE3', '#D1BBD7', '#CAACCB', '#BA8DB4',
'#AE76A3', '#AA6F9E', '#994F88', '#882E72', '#1965B0',
'#437DBF', '#5289C7', '#6195CF', '#7BAFDE', '#4EB265',
'#90C987', '#CAE0AB', '#F7F056', '#F7CB45', '#F6C141',
'#F4A736', '#F1932D', '#EE8026', '#E8601C', '#E65518',
'#DC050C', '#A5170E', '#72190E', '#42150A']
indexes = [[9], [9, 25], [9, 17, 25], [9, 14, 17, 25], [9, 13, 14, 17,
25], [9, 13, 14, 16, 17, 25], [8, 9, 13, 14, 16, 17, 25], [8,
9, 13, 14, 16, 17, 22, 25], [8, 9, 13, 14, 16, 17, 22, 25, 27],
[8, 9, 13, 14, 16, 17, 20, 23, 25, 27], [8, 9, 11, 13, 14, 16,
17, 20, 23, 25, 27], [2, 5, 8, 9, 11, 13, 14, 16, 17, 20, 23,
25], [2, 5, 8, 9, 11, 13, 14, 15, 16, 17, 20, 23, 25], [2, 5,
8, 9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25], [2, 5, 8, 9, 11,
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 8, 9, 11,
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
13, 14, 15, 16, 17, 19, 21, 23, 25, 27], [2, 4, 6, 7, 8, 9, 11,
13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4, 6, 7, 8,
9, 11, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26, 27], [1, 3, 4,
6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 21, 23, 25, 26,
27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 20,
22, 24, 25, 26, 27], [1, 3, 4, 6, 7, 8, 9, 10, 12, 13, 14, 15,
16, 17, 18, 20, 22, 24, 25, 26, 27, 28], [0, 1, 3, 4, 6, 7, 8,
9, 10, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 25, 26, 27, 28]]
if lut is None or lut < 1 or lut > 23:
lut = 22
# trim the hash symbol from the color start and return a list of hex colors
return [ clrs[i][1:] for i in indexes[lut-1] ]
def generate_discrete_rainbow(folder):
"""
Generate 'rainbow_discrete' colormap.
"""
template_str = """# Discrete rainbow color scheme with $colors_len color$s
# from Paul Tol's website: https://personal.sron.nl/~pault/
# Set color cycle
axes.prop_cycle : cycler('color', $colors_list)
"""
template = Template(template_str)
for i in range(1, 24):
colors_list = __rainbow_discrete(i)
colors_len = len(colors_list)
file_path = folder / f'discrete-rainbow-{colors_len}.mplstyle'
with open(file_path, 'w') as f:
f.write(template.substitute(colors_list=colors_list, colors_len=colors_len, s='s' if colors_len > 1 else ''))
if __name__ == '__main__':
output_folder = Path(__file__).parent
generate_discrete_rainbow(output_folder) |
On his website Paul Tol proposes which colors to use when more than the regular 7 in the seven in the
std-colorsare needed. As different rainbow subsets are used depending on the number of colors needed, a simple skipping of colors from the maximum of 23 is not the proposed way, thus all 23 styles need to be included.