MATLAB: Colormap won’t change

colormapcolorscolours

Colormap no longer changes the colour map used by a plot?
I declare some new colours:
cols = [0.60 0.86 0.91; % skyblue
0.90 0.96 0.94; % paleblue
0.82 0.71 0.48; % palebrown
0.87 0.42 0.41; % pink
0.97 0.65 0.52; % palepink
0.98 0.84 0.66; % sand
0.58 0.74 0.81; % midblue
0.60 0.86 0.72; % steel
1.00 0.97 0.50; % paleyellow
0.80 0.89 0.25; % lime
0.30 0.75 0.59; % turquoise
0.70 0.71 0.27; % olive
0.50 0.80 0.32; % palegreen
0.98 0.78 0.20; % mustard
0.70 0.57 0.46]; % chocolate
Then I construct my data array (multiple series)
Then I open a figure, and set the colormap to my colours.
Then I create axes, and again set their colormap to my colours.
I plot my series, and again set the colormap (both syntaxes this time).
Finally a legend, with – yes! – another colormap call.
f1 = figure;
orient landscape;
colormap(f1,cols)
ax = axes('Position',[0.1,0.1,0.8,0.8],'Box','on');
colormap(ax,cols)
plot(xvy,dy,'LineWidth',1);
colormap(ax,cols)
colormap(cols)
legend(labs,'Location','southwest')
colormap(ax, cols)
It still just displays seven Parula colours and recycles them for my remaining series (I have ten).
Obviously I've tried colormap calls everywhere separately as well.
Thanks for any obvious error spotting!
Harry

Best Answer

You are plotting lines using plot, which determines the line color using the axes ColorOrder property. This is explained in the plot documentation: " plot uses colors and line styles based on the ColorOrder and LineStyleOrder properties of the axes."
So line color has absolutely nothing to do with the colormap, and has absolutely nothing to do with parula: the color of lines is defined by the axes ColorOrder property. You might like to look at the line colors: do you see all of those colors in parula? Where?
You can search for "MATLAB Line ColorOrder" and find plenty of help:
If you want simple working examples of how to set the line ColorOrder, then have a look at the examples of one of my FEX submissions, e.g.:
Otherwise you can simply explicitly define the color when calling plot, or by setting the line color property once the lines have been created. Whatever works for you.