plot_contributions.m: compatibility fixes for Octave

— use zeros instead of NaNs when decomposing between positive and negative
  contributions; otherwise some contributions are not plotted
— the bar() function returns a column-vector of graphic handles, while on
  MATLAB it returs a row-vector
time-shift
Sébastien Villemot 2021-01-29 15:19:00 +01:00
parent 5da473ac66
commit 3e6224e0b6
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
1 changed files with 8 additions and 4 deletions

View File

@ -186,8 +186,8 @@ hold on
cc = contribution(:,2:end);
% Limit the matrices to what we care about
ccneg = cc(:,1:length(vnames)); ccneg(ccneg>=0) = nan;
ccpos = cc(:,1:length(vnames)); ccpos(ccpos<0) = nan;
ccneg = cc(:,1:length(vnames)); ccneg(ccneg>=0) = 0;
ccpos = cc(:,1:length(vnames)); ccpos(ccpos<0) = 0;
H = bar(1:ds.nobs, ccneg, 'stacked');
if ~isoctave && ~matlab_ver_less_than('9.7')
% For MATLAB ≥ R2019b, use the same color indexing scheme as with older releases
@ -201,5 +201,9 @@ lhs = strrep(lhs, '_', '\_');
title(sprintf('Decomposition of %s', lhs))
vnames = strrep(vnames,'_','\_');
legend([H, line_], [vnames, lhs], 'location', 'northwest');
if ~isoctave
legend([H, line_], [vnames, lhs], 'location', 'northwest');
else
% Under Octave, H is a column vector
legend([H; line_], [vnames, lhs], 'location', 'northwest');
end