equally spaced nice colors?

I'm currently using seaborn to get equally spaced nice colors:

        import seaborn as sns
        colors = np.array(sns.color_palette("hls", len (solution)))

Now that mpl has all new improved color models, do I still need to use sns
or can I easily do something similar with mpl directly?

You should be able to use the tab10/tab20 etc. colormaps directly, if
that's a similar palette:
https://matplotlib.org/examples/color/colormaps_reference.html

···

On Fri, Feb 22, 2019 at 8:08 AM Neal Becker <ndbecker2 at gmail.com> wrote:

I'm currently using seaborn to get equally spaced nice colors:

        import seaborn as sns
        colors = np.array(sns.color_palette("hls", len (solution)))

Now that mpl has all new improved color models, do I still need to use sns
or can I easily do something similar with mpl directly?

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190401/5a2b3502/attachment.html&gt;

Dear Neal,

Answer 1: If you are looking for equally spaced colors from a given colormap.

Choose your favorite ?nice" colormap from here.
https://matplotlib.org/tutorials/colors/colormaps.html

I use viridis for example.

import matplotlib.pyplot as plt

cmap = plt.get_cmap('viridis')
print('Default number of colors in the lookup table:', len(cmap.colors)) # default: 256 colors
print('First color:', cmap.colors[0])
print('Last color:', cmap.colors[-1])
print('10 equally spaced colors:', cmap(np.linspace(0, 1, 10)))
print('wrong example:', cmap(range(10)))

And you?ll get this:

Default number of colors in the lookup table: 256
First color: [0.267004, 0.004874, 0.329415]
Last color: [0.993248, 0.906157, 0.143936]
10 equally spaced colors: [[ 0.267004 0.004874 0.329415 1. ]
[ 0.281412 0.155834 0.469201 1. ]
[ 0.244972 0.287675 0.53726 1. ]
[ 0.190631 0.407061 0.556089 1. ]
[ 0.147607 0.511733 0.557049 1. ]
[ 0.119699 0.61849 0.536347 1. ]
[ 0.20803 0.718701 0.472873 1. ]
[ 0.430983 0.808473 0.346476 1. ]
[ 0.709898 0.868751 0.169257 1. ]
[ 0.993248 0.906157 0.143936 1. ]]
wrong example: [[ 0.267004 0.004874 0.329415 1. ]
[ 0.26851 0.009605 0.335427 1. ]
[ 0.269944 0.014625 0.341379 1. ]
[ 0.271305 0.019942 0.347269 1. ]
[ 0.272594 0.025563 0.353093 1. ]
[ 0.273809 0.031497 0.358853 1. ]
[ 0.274952 0.037752 0.364543 1. ]
[ 0.276022 0.044167 0.370164 1. ]
[ 0.277018 0.050344 0.375715 1. ]
[ 0.277941 0.056324 0.381191 1. ]]

See these for details.
https://matplotlib.org/api/cm_api.html#matplotlib.cm.get_cmap
https://matplotlib.org/tutorials/colors/colormap-manipulation.html#getting-colormaps-and-accessing-their-values

Answer 2: If you are looking for "evenly-spaced colors in a circular color space" with constant brightness and saturation like hls in seaborn,

I guess matplotlib doesn?t support that type of colormaps for the moment as you can find here https://matplotlib.org/tutorials/colors/colormaps.html.
You need to make your own or find ones that someone made like hls in seaborn.

Best regards,

Kotaro

//================//================//
Paul Scherrer Institut
Kotaro SAITO ???
Laboratory for Neutron Scattering and Imaging
WHGA/348
5232 Villigen PSI, Schweiz
+41 56 310 3179
kotaro.saito at psi.ch

//================//================//

···

2019/02/22 14:01?Neal Becker <ndbecker2 at gmail.com>???:

I'm currently using seaborn to get equally spaced nice colors:

       import seaborn as sns
       colors = np.array(sns.color_palette("hls", len (solution)))

Now that mpl has all new improved color models, do I still need to use sns
or can I easily do something similar with mpl directly?

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page