area, stairs

32 visualizaciones (últimos 30 días)
Hamed Amini
Hamed Amini el 20 de Jul. de 2011
Editada: Bill Tubbs el 30 de Mzo. de 2024 a las 18:47
Is there any property setting for 'area' function which generates the 'straits' for the boundary of the colored regions instead of 'plot' curves?

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 20 de Jul. de 2011
% Random row input
x = 1:10;
y = rand(1,10);
% Normal area chart
subplot(3,1,1)
area(x,y)
% Stairs chart (non area)
subplot(3,1,2)
stairs(x,y)
% Stairs area
subplot(3,1,3)
x = [x;x];
y = [y;y];
area(x([2:end end]),y(1:end))
  1 comentario
Hamed Amini
Hamed Amini el 20 de Jul. de 2011
Very Clever! Thanks Oleg.

Iniciar sesión para comentar.

Más respuestas (1)

Bill Tubbs
Bill Tubbs el 30 de Mzo. de 2024 a las 4:33
Editada: Bill Tubbs el 30 de Mzo. de 2024 a las 18:47
Building on Oleg's answer I wrote a function for doing the same thing with a stacked area plot. However, the data in the x and Y arguments here are aligned vertically in the rows, not horizontally in the columns.
function area_step_plot(x, Y)
assert(size(x, 2) == 1)
nx = size(x, 1);
Y = Y(1:nx-1, :); % final y-values are not used
ny = size(Y, 2);
X = [x x]';
X2 = X(2:end-1)';
Y2 = reshape(permute(cat(3, Y, Y), [3 1 2]), [], ny);
area(X2, Y2)
end
The Y argument can be a matrix of column vectors containing different data series.
x = (1:10)';
Y = rand(10, 3); % Note: last row is not plotted
area_step_plot(x, Y)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by