I am interested in using the cmap('hot') from Matplotlib as a Bokeh palette.
First, I choose the Matplotlib colormap subset given by
from Matplotlib.pyplot as plt
colors_mpl = [i for i in plt.get_cmap('hot')(np.linspace(0.05, 0.95, 6))]
Initially, given an set of RGB colors, I could convert to html by using the built-in function to_hex.
from matplotlib.colors import to_hex
colors_html = [to_hex(rgb/255) for rgb in colors_mpl]]
However, the output I get is not the expected as I get very small differences between colors:
['#000000', '#010000', '#010000', '#010100', '#010100', '#010101']
The expected output is
['#2a0000', '#a30000', '#ff1d00', '#ff9800', '#ffff1b', '#ffffd0']
Any ideas of how to convert the colormap to html properly?
Don't divide by 255, colors_mplt are already in scale 0-1:
colors_html = [to_hex(rgb) for rgb in colors_mpl]
# out
# ['#2a0000', '#a30000', '#ff1d00', '#ff9800', '#ffff1b', '#ffffd0']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With