<jupyter_start><jupyter_text>Export CMasher colormaps and import them into Tableau If you use this tutorial please acknowledge it with a link to this GitHub document or webpage. Also please acknowledge CMasher if you are using its colormaps. How to acknowledge CMasher is given here https://cmasher.readthedocs.io/community_guidelines.html  Get colormaps from CMasher<jupyter_code># Import packages
import cmasher as cmr

# in case you don't have cmasher, install it
#!pip install cmasher
cmr.__version__
# Get colormaps
cmr.cm.cmap_d.keys()
# Get type of the colormaps
cmr.cm.cmap_cd.keys()
# Find which colormap is within which cathegory
# cmr.cm.cmap_cd
# There are only sequential and diverging colormaps
# We obtain names of colormaps using only those that do not end with '_r' since they are the reversed version of each colormap

sequential_colormap = [y for y in cmr.cm.cmap_cd['sequential'] if not y.endswith('_r')]
diverging_colormap = [y for y in cmr.cm.cmap_cd['diverging'] if not y.endswith('_r')]<jupyter_output><empty_output><jupyter_text>Get HEX values<jupyter_code># Get the HEXZ values of each sequential colormaps 
# Export them in range of: 0.15 to 0.85 -> you can export the full range if you prefer.
all_sequential_maps_hex = []
for colormap in sequential_colormap:
    cmp = cmr.take_cmap_colors('cmr.{}'.format(colormap), None, cmap_range=(0.15, 0.85), return_fmt='hex')
    all_sequential_maps_hex.append(cmp)
# Get the hex values of the diverging colormaps; in range 0.15 to 0.85
all_diverging_maps_hex = []
for colormap in diverging_colormap:
    cmp = cmr.take_cmap_colors('cmr.{}'.format(colormap), None, cmap_range=(0.15, 0.85), return_fmt='hex')
    all_diverging_maps_hex.append(cmp)<jupyter_output><empty_output><jupyter_text>Transform colormaps into Tableau format<jupyter_code># Get all the sequential colormaps in the format that is required in Tableau
for i, hexes in enumerate(all_sequential_maps_hex):
    print('<color-palette name='+'"'+'{}'.format(sequential_colormap[i])+'" ' +'type="ordered-sequential">')
    for j, col in enumerate(hexes):
        print('    <color>'+'{}'.format(hexes[j])+'</color>')
    print('</color-palette>')
# Get all the diverging colormaps in the format that is required in Tableau
for i, hexes in enumerate(all_diverging_maps_hex):
    print('<color-palette name='+'"'+'{}'.format(diverging_colormap[i])+'" ' +'type="ordered-diverging">')
    for j, col in enumerate(hexes):
        print('    <color>'+'{}'.format(hexes[j])+'</color>')
    print('</color-palette>')<jupyter_output><empty_output><jupyter_text>Parameters.tps format Copy the output of the last two outputs into the Tableau file: Preferences.tps<jupyter_code>'''
<?xml version='1.0'?>

<workbook>
    <preferences>   
    
    
    PLACE HERE THE OUTPUTS FROM THE COLORMAPS
    
    
    </preferences>
</workbook>
'''<jupyter_output><empty_output><jupyter_text>An example of the Parameters.tps file An example of the Tableau preference file with diverging colormap named Pride and sequential colormap named Rainforest<jupyter_code>'''
<?xml version='1.0'?>

<workbook>
    <preferences>  

        <color-palette name="Pride" type="ordered-diverging">
            <color>#160E28</color>
            <color>#2A194D</color>
            <color>#2C2D6D</color>
            <color>#22467B</color>
            <color>#1E5C7E</color>
            <color>#2C707E</color>
            <color>#42827E</color>
            <color>#5A947D</color>
            <color>#73A679</color>
            <color>#94B86E</color>
            <color>#B9C85C</color>
            <color>#E2D740</color>
            <color>#F9CD1E</color>
            <color>#F7AD0D</color>
            <color>#F08F0F</color>
            <color>#E6711C</color>
            <color>#D7562A</color>
            <color>#C63D37</color>
            <color>#B12543</color>
            <color>#980E4E</color>
            <color>#7C0154</color>
            <color>#5B0B4C</color>
            <color>#3B1035</color>
            <color>#1F0A1A</color>
        </color-palette>
        
        <color-palette name="Rainforest" type="ordered-sequential">
            <color>#33034A</color>
            <color>#3A0161</color> 
            <color>#3E0374</color> 
            <color>#3E1086</color> 
            <color>#392291</color> 
            <color>#313193</color> 
            <color>#254091</color> 
            <color>#194B8E</color> 
            <color>#0C5589</color> 
            <color>#035F84</color> 
            <color>#016781</color> 
            <color>#036F7E</color> 
            <color>#07787A</color> 
            <color>#0B7F77</color> 
            <color>#118772</color> 
            <color>#188E6D</color> 
            <color>#239665</color> 
            <color>#329E5B</color> 
            <color>#41A550</color> 
            <color>#55AB41</color> 
            <color>#6CB02E</color> 
            <color>#83B419</color> 
            <color>#9DB602</color> 
            <color>#B2B811</color> 
            <color>#C6BB2E</color> 
            <color>#D6BF4A</color> 
            <color>#E1C361</color> 
            <color>#EDC87D</color>
        </color-palette>
        
    </preferences>
</workbook>
'''<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13671949589459614, 'fraction_numerical': 0.04716440710330342, 'mean_word_length': 2.9324324324324325, 'pattern_counts': {'":': 0, '<': 147, '<?xml version=': 2, '>': 148, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '193716', 'license': 'MIT', 'n_tokens_mistral': 1997, 'n_tokens_neox': 1832, 'n_words': 373, 'path': 'Tableau_CMasher.ipynb', 'repo_name': 'rdzudzar/Tableau_Colormaps', 'size': '5237'}