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])
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])
Comments
Post a Comment