Can I use colormap to set color of my cumulative area chart in area()?

2 views (last 30 days)
If so, how should I use it?
I tried to put something like colormap(map) on some different places but they just didn't work.
  2 Comments
稚萌 王
稚萌 王 on 1 Dec 2022
A simple example of my question is like follows:
a=[1,2,3,4,5]';
b=2*a; % 2,4,6,8,10
c=3*a; % 3,6,9,12,15
x_axis=1:size(a,1);
area(x_axis,[a,b,c],0);
colormap("summer");
legend('a','b','c');
The color of the figure I got is not "summer" in the colormap but more like something default in the command area().
How should I edit the codes to make the colormap command work? Thanks!

Sign in to comment.

Answers (1)

Voss
Voss on 1 Dec 2022
Edited: Voss on 1 Dec 2022
area dioesn''t use the figure's colormap directly, but it does use the axes' ''ColorOrder' by default, so maybe something like this is what you want to do:
a = [1;2;3;4;5];
b = 2*a;
c = 3*a;
data = [a,b,c];
x_axis = 1:size(a,1);
area(x_axis,data,0);
set(gca(),'ColorOrder',summer(size(data,2)));
legend('a','b','c')

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!