Area plot matlab colors

43 次查看(过去 30 天)
Hi there,
I have a Matlab script like this :
b2=area([array1+array2-array3+array4],'EdgeColor','none','FaceAlpha',0.3); %array1,2,3,4 are equal size arrays
In this way, the sum inside brackets has the same color and I would like each array of this sum to have different color. How can I specify it to have 4 different colors, 1 for each array?
Thank you for your time.

采纳的回答

Star Strider
Star Strider 2022-11-12
With so little information, I can only suggest one approach, that being serial area calls or concatenating the ‘array’ variables.
Perhaps —
% x = 1:10;
array1 = rand(1,10);
array2 = rand(1,10);
array3 = rand(1,10);
array4 = rand(1,10);
figure
b2=area([array1+array2-array3+array4],'EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Original')
figure
b2=area([array1; array2-array3; array4].','EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Separated & Concatenated 1')
figure
b2=area([array1; array2; -array3; array4].','EdgeColor','none','FaceAlpha',0.3);
xlim([1 10])
title('Separated & Concatenated 2')
This operation:
array2-array3
may prevent the vectors in that term from being separated into two different arrays. I present two different way s of dealing with it here
.
  5 个评论
panagiotis skrempos
panagiotis skrempos 2022-11-14
Perfect...That exactly what i needed, thank you so much for your help and your time. I am really grateful
Star Strider
Star Strider 2022-11-14
As always, my pleasure!
This was an interesting problem!
.

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2022-11-12
figure
hold on
area(array1,'EdgeColor','none','FaceColor','r');
area(array2,'EdgeColor','none','FaceColor','b');
area(array3,'EdgeColor','none','FaceColor','g');
area(array4,'EdgeColor','none','FaceColor','m');
See to it that, the areas are in the decreasing order.

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by