bar graph : How to show each bar with different base value ?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I would like to show use bar graph. But each bar has different base line. So, I wrote the following codes. However, it gives error. Could you please help me, how to do this with matlab
my codes are;
figure(1);
x=[1 2 3 4]; y1=[928,1417; 2166,3625; 2278,3401; 1,2]; y2=[197,271; 141,212; 34,150; 1,2];
b1 = bar(x,y1, 'facecolor', 'y'); hold on; b2 = bar(x,y2, 'facecolor', 'b');
b1(1).baseValue=928; % <== it gives error here. How to solve this problem ? b1(2).baseValue=2166; b1(3).baseValue=2278;
0 comentarios
Respuestas (3)
dpb
el 14 de Jun. de 2016
Apparently you've got an earlier release than R2014b, maybe? The ".dot" notation for properties wasn't implemented prior, use set instead--
set(b(1),'basevalue',928); % works fine here (R2012b)
However, the rest will have troubles--
b1(2).baseValue=2166;
the baseline is only a single value for each bar series; hence setting b1(2) to something different than b1(1) will simply replace the first with the second value.
And,
b1(3).baseValue=2278;
there are only two b1 handles so the above will error on a bounds error.
The only way to have a different baseline per bar will be to have only a single bar per bar plot or make the patch objects directly from primitives.
0 comentarios
Brad Allen
el 20 de Oct. de 2016
Editada: Brad Allen
el 20 de Oct. de 2016
I was just having this same issue, also couldn't figure it out. It would seem that no matter which way I changed the basevalue (either separate bar charts or using set() or barhandle.BaseValue), it would always change to the last one I set. For example:
data = [1,2,3;4,5,6]';
hbar = bar(data);
set(hbar(1), 'BaseValue', 2);
set(hbar(2), 'BaseValue', 5);
% This results in the BaseValue for both sets = 5
% same happens if you do this
hbar1 = bar(data(:,1),'BaseValue',2);
hold on
hbar2 = bar(data(:,2),'BaseValue',5);
% or if you do this
hbar1 = bar(data(:,1));
hold on
hbar2 = bar(data(:,2));
hbar1.BaseValue = 2;
hbar2.BaseValue = 5;
% It always results in a BaseValue of 5 for both datasets...
It's strange because if you set foo = get(barhandle.BaseValue), you will get a cell array that contains the same basevalue in each cell, but Matlab (R2014b) returns an error if you try to assign a cell array to barhandle.Basevalue.
0 comentarios
Ver también
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!