How can I plot multiple areas in the same graph?

I have 6 vectors and I want to make a plot of their areas, exactly like the image attached.
Is there any way to acomplished that? Thanks a lot!

 Akzeptierte Antwort

Kelly Kearney
Kelly Kearney am 19 Mai 2014

2 Stimmen

Here's an example of the stacking area plots idea:
% Sample data
data = bsxfun(@plus, normpdf(linspace(0,6,100), 2, 0.5)', rand(100,6)*0.1);
data = bsxfun(@plus, data, rand(1,6)*0.5 + 0.25);
% Plot
n = size(data,2);
base = min(data) - 0.01; % Base value for each dataset
bloc = (0:n-1) * 0.5; % Where that base value will be located
axes; hold on;
for ii = 1:size(data,2)
h(ii) = area(data(:,ii)-base(ii)+bloc(ii), bloc(ii));
end
uistack(h, 'top');

3 Kommentare

Hi, Is this method still working in matlab 2015a? The code below seems to update base value for each vector so the base value for all vectors is actually the last bloc(ii).
area(data(:,ii)-base(ii)+bloc(ii), bloc(ii))
In Matlab 7.0 I can assign different base value to each vector I plot using function "area". Is there anything I missed?
Thanks, Hank
You're right, 2014b+ versions seem to reset the base value for all area plots on an axis together, rather than allowing different ones per area object, as in previous versions. I'd submit a bug report on that... seems like an undocumented (and very inconvenient) change, at the least.
Hsin-Hua Wang
Hsin-Hua Wang am 23 Jun. 2016
Answering my own question one year ago, this feature has not been fixed yet, meaning one baseline value for one axes. I end up assign every plot their own axes and hide everything for those axes.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Héctor
Héctor am 19 Mai 2014

0 Stimmen

thats what I was looking for, thanks!
Ullekh Gambhira
Ullekh Gambhira am 16 Jun. 2018

0 Stimmen

I am facing the same issue, I solved it by using "Shade area between two curves" function by John Bockstege. The file exchange link for this function is below:
https://www.mathworks.com/matlabcentral/fileexchange/13188-shade-area-between-two-curves
It does not consider base value, but basically shades the area between two lines. So one line can be your vector and the other can be a baseline*ones(size(x)).
Hope this helps.
Regards, Ullekh

Kategorien

Mehr zu Discrete Data Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by