Bar Graph that does not start from zero

Is there a way to plot a bar graph that does not start from y=0 to its value. I want the bars to be shifted up during on the offset at the given time. For one of the bars instead of starting from y=0 to 5, I want it to start from y=3 to y=5. For example, I want to plot a sine function from 0 to 2*pi which has an offset of 3 (shifted up 3) using the bar graph function to show its amplitude over the time of the function. So essentially instead of starting from zero it will start at 3.
Is this possible in matlab or is there another way around it using some sort of bar graph.

Respuestas (3)

Knut
Knut el 20 de Oct. de 2016
Editada: Knut el 20 de Oct. de 2016
Google sent me here in the search for a "bipolar" bar graph. It is my understanding that the baseline property is global, while I (and the thread starter?) actually wants to have 2-element bar elements that start at some y value and end at another y value. Something ala this:
v = [1 3 -1; ...%bottom of each element
12 17 1]; %top of each element
[K,N] = size(v);
assert(K==2);
assert(N>=1);
assert(all(diff(v)>=0))
sq_x = [0; 1; 1; 0; 0];
sq_y = [0; 0; 1; 1; 0];
patch(sq_x*0.5 + (1:N)-0.25, sq_y .* diff(v) + v(1,:), 'b')
set(gca, 'XTick', 1:N)

1 comentario

Steven Lord
Steven Lord el 20 de Oct. de 2016
So you want something a bit closer to a boxplot from Statistics and Machine Learning Toolbox or perhaps an errorbar plot?

Iniciar sesión para comentar.

Michael
Michael el 7 de Abr. de 2025

0 votos

Add a spacer bar below each set of stacked bars to be plotted, then make it transparent with the alpha controls.
x = [1 2 3 4];
y1 = [2 0 1 3]; % spacer bars to be made transparent
y2 = [3 2 4 1];
y3 = [1 2 2 1];
figure
hdl = bar(x,[y1;y2;y3],'stacked');
grid on;
set(hdl(1),'FaceAlpha',0,'EdgeAlpha',0);

Categorías

Preguntada:

AG
el 19 de Jul. de 2012

Respondida:

el 7 de Abr. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by