How-to: Display the colourmaps availabe in Towerpy and convert to Greyscale.#
Daniel Sanchez-Rivas1 and Miguel A. Rico-Ramirez2
1Department of Meteorology, University of Bonn, Bonn, 53121, DE
2Department of Civil Engineering, University of Bristol, Bristol, BS8 1TR, United Kingdom
This notebook describes the process to display the colourmaps available in Towerpy.
Import relevant packages#
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
import towerpy as tp
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import matplotlib as mpl
2 import matplotlib.pyplot as plt
3 import matplotlib.colors as mcolors
ModuleNotFoundError: No module named 'matplotlib'
Read-in the Towerpy colourmaps#
First, we’ll read the colourmaps available in Towerpy.
tpcm = list(mpl.colormaps)
tpcm[:] = [i for i in tpcm if i.startswith('tpy')]
# Create a list of Radar-related colourmaps
tp_rad_lsc = [i for i in tpcm if 'rad' in i and 'lsc' in i]
tp_rad_lc = [i for i in tpcm if 'rad' in i and 'lc' in i]
# Create a list of Diverging colourmaps
tp_div_lsc = [i for i in tpcm if 'div' in i and 'lsc' in i]
tp_div_lc = [i for i in tpcm if 'div' in i and 'lc' in i]
# Create a list of Perceptually Uniform Sequential colourmaps
tp_unfseq_lsc = [i for i in tpcm if 'useq' in i and 'lsc' in i]
tp_unfseq_lc = [i for i in tpcm if 'useq' in i and 'lc' in i]
We will use the Greyscale conversion 1 described in the Matplotlib documentationfor performing greyscale conversions. Please refer to their webpage for more details on the greyscale simulation process.
cm2plot = tp_rad_lsc
tp.datavis.tpy_cm.plot_color_gradients_grayscale(cm2plot[:int(len(cm2plot)/2)])
cm2plot = tp_div_lsc
tp.datavis.tpy_cm.plot_color_gradients_grayscale(cm2plot[:int(len(cm2plot)/2)])
cm2plot = tp_unfseq_lsc
tp.datavis.tpy_cm.plot_color_gradients_grayscale(cm2plot[:int(len(cm2plot)/2)])
Finally, we plot a sequential colourmap to show the greyscale conversion.
tp.datavis.tpy_cm.plot_examples([tp_unfseq_lsc[2], tp_unfseq_lsc[13]])
tp.datavis.tpy_cm.plot_color_gradients_grayscale([tp_unfseq_lsc[2], tp_unfseq_lsc[13]])
References#
Matplotlib Grayscale conversion-Classes of colormaps https://matplotlib.org/stable/users/explain/colors/colormaps.html#grayscale-conversion