From 3e6224e0b6306008f40bc8bb0e7809bb76cfbabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Fri, 29 Jan 2021 15:19:00 +0100 Subject: [PATCH] plot_contributions.m: compatibility fixes for Octave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — 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 --- matlab/plot_contributions.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/matlab/plot_contributions.m b/matlab/plot_contributions.m index e47ea8775..a1e6c902d 100644 --- a/matlab/plot_contributions.m +++ b/matlab/plot_contributions.m @@ -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