Change underlying colormap for 'plot', just like in 'area'

I'm trying to have a figure with various subplots, showing portfolio composition with area plots and portfolio returns with a normal (line) plots. For the area plot, Matlab is using the default colormap Jet, and I can change this by using
colormap(summer)
for example. Now it makes sense to plot the time series of returns of each assets in the same color as it has in the area plot, however, Matlab always uses the 'line' colormap, which has the problem that it repeats itself after the seventh color, making curves 8 and 9 blue and green like curves 1 and 2. typing colormap(summer), as above, does affect the 'area' command, but not the 'plot' command. I'm working with many subplots, hence a solution that does not have to be applied to every single plot would be best.

 Accepted Answer

the cyclist
the cyclist on 8 Aug 2013
Edited: the cyclist on 8 Aug 2013

4 Comments

Thanks for the quick reply. Now using 'set(0,'DefaultAxesColorOrder',summer)' works and changes the color, however, the colors are not cycling, but all lines are plotted in the same color, namely the first one in the set. Do you have an idea how to make them cycle through?
If you are using a plot command each time through the loop, like this
figure
hold on
for i=1:4
plot(rand(3,1))
end
then each plot command is independent from each other one, and chooses the first color of ColorOrder.
There are a couple solutions. If you can collect the data into one array, then plot all at once,
figure
plot(rand(3,4))
then you will cycle through the ColorOrder automatically.
If you can't do that, then assign a handle to each line ...
figure
hold on
for i=1:4
h(i) = plot(rand(3,1))
end
and you can set the color of each line:
set(h(i),'Color',<color you want goes here>)
There is probably a cleaner way to that last part, assigning all colors at once to the entire h vector.
here is my code; I am plotting several lines B1, B2, ... in one graph via [B1,B2,B3,...]. When not changing any colormap and using the default 'line' colormap, the colors cycle through without a problem.
clf;
figure(8);
subplot(2,2,1),
area(transpose(Weight)); % this works fine with any colormap
subplot(2,2,2),
plot(ret2tick(PORT),'LineWidth',2,'color','black'); hold on
plot(ret2tick([B1,B2,B3,B4,B5,B6,B7,B8,B9]),'--'); % this does not
I now got it, it was necessary to type the command
set(0,'DefaultAxesColorOrder',summer(9))'
where '9' is the number of colors that the colormap should have.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!