python - Use colormaps along with matplotlib cycler -


i use matplotlib cycler colors palettable.

cycler looks this:

from cycler import cycler plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +                            cycler('linestyle', ['-', '--', ':', '-.']))) 

how replace color list above color map obtain palettable?

import palettable cmap = palettable.colorbrewer.diverging.prgn_11.mpl_colormap 

for answer, not critical use palettable, important know how use colormap.

cycler needs iterable assigned 'colors'.

here way generate one:

[plt.get_cmap('jet')(1. * i/n) in range(n)] 

so original example:

plt.rc('axes', prop_cycle=(cycler('color', ['r', 'g', 'b', 'y']) +                            cycler('linestyle', ['-', '--', ':', '-.'])))  x = [1,2,3,4] in range(4):     plt.plot([_ + _ in x]) 

enter image description here

to modified list 'jet' colormap:

n = 4 # number of colors new_colors = [plt.get_cmap('jet')(1. * i/n) in range(n)]  plt.rc('axes',         prop_cycle=(cycler('color', new_colors) +                     cycler('linestyle', ['-', '--', ':', '-.'])))  in range(4):     plt.plot([_ + _ in x]) 

enter image description here


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -