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

4 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
Jeffrey Clark
Jeffrey Clark on 30 Nov 2022
@稚萌 王, all questions should include what you have done so far so that we have some idea of what the question is. Attach code (.m) and data files (.txt, .csv, .mat etc) or at least the portion of code in a "Insert a line of code" box and error message like:
%code example
this = ~does %work
Unrecognized function or variable 'does'.
稚萌 王
稚萌 王 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')

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!