Why do the bars on my plot overlap when I create a BAR plot with only 2 bars?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
If I draw a BAR plot with 2 bars, and the distance between the bars is less than 0.8, MATLAB will draw them as overlapping. The following code will reproduce the problem:
bar([.25 .5],[2 3])
Risposta accettata
MathWorks Support Team
il 27 Giu 2009
This bug has been fixed for Release 14 (R14). For previous releases, please read below for any possible workarounds:
To work around the problem, you can hard code the bar width, using the following code as a guide:
barWidth = 0.2;
bar([.25 .5], [2 3], barWidth)
In MATLAB 6.5 (R13) code, the source of the problem is on lines 150 and 233 of $MATLAB/toolbox/matlab/specgraph/makebars.m, where $MATLAB denotes your root MATLAB directory. (This code may reside on different line numbers for previous releases of MATLAB.) In the case where there are 2 bars, these pieces of code return an empty logical array when they are expected to return either logical(0) or logical(1). One way to work around this problem is to replace each of the two sections of code (lines 147-151 and lines 233-244) with the following code:
if length(y)==1 | max(diff(y))==0,
equal = []; % Special case
else
equal = max(abs(diff(diff(y)))) <= max(max(abs(y)))*sqrt(eps);
if isempty(equal)
equal = 0;
end
end
PLEASE NOTE: This modification is not fully tested, and therefore cannot be guaranteed to work in all cases.
PLEASE NOTE: The file "makebars.m" is used by several graphics functions, including BAR, BAR3, BARH, BAR3H, and HIST. Therefore, changing the code puts these functions at risk of not working properly.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!