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

5 vues (au cours des 30 derniers jours)
稚萌 王
稚萌 王 le 30 Nov 2022
Modifié(e) : Voss le 1 Déc 2022
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 commentaires
Jeffrey Clark
Jeffrey Clark le 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'.
稚萌 王
稚萌 王 le 1 Déc 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!

Connectez-vous pour commenter.

Réponses (1)

Voss
Voss le 1 Déc 2022
Modifié(e) : Voss le 1 Déc 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')

Catégories

En savoir plus sur Red dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by