# Stacked bar plot with positive and negative values

15 messages
Open this post in threaded view
|

## Stacked bar plot with positive and negative values

 Hello, I am trying to plot a bar plot, stacked, containing positive and negative value. Unfortunately, I don't manage to get a good result with the bar function. The stacked bar plot works well with positive values.  z=[1 2 3  4 3 1]  h = bar (z, 'stacked');   And does not wok well with negative value. It seems the values are printed on top of each other.  figure  z=[1 -2 3  4 3 1]  h = bar (z, 'stacked'); Do you know a way to work around this? Kind regards, Olivier -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 On Sun, Apr 19, 2020 at 9:05 AM Olive <[hidden email]> wrote:Hello, I am trying to plot a bar plot, stacked, containing positive and negative value. Unfortunately, I don't manage to get a good result with the bar function. The stacked bar plot works well with positive values.  z=[1 2 3  4 3 1]  h = bar (z, 'stacked'); And does not wok well with negative value. It seems the values are printed on top of each other.  figure  z=[1 -2 3  4 3 1]  h = bar (z, 'stacked'); Do you know a way to work around this? Kind regards, Olivier -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html The output is what I would expect to see (bar of height 1, overlaid with a bar of height -2, overlaid with a bar of height 3) so you only see the last bar.  What are you expecting to see?Tony Richardson
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Dear Tony,Thank you for your answer. For what I know, usually stacked bar would look like this (same data in excel):The negative value block would be in the negative side and the positive value on the positive side, without overlap.Kind regards,OlivierOn Sun, 19 Apr 2020 at 17:26, Tony Richardson <[hidden email]> wrote:On Sun, Apr 19, 2020 at 9:05 AM Olive <[hidden email]> wrote:Hello, I am trying to plot a bar plot, stacked, containing positive and negative value. Unfortunately, I don't manage to get a good result with the bar function. The stacked bar plot works well with positive values.  z=[1 2 3  4 3 1]  h = bar (z, 'stacked'); And does not wok well with negative value. It seems the values are printed on top of each other.  figure  z=[1 -2 3  4 3 1]  h = bar (z, 'stacked'); Do you know a way to work around this? Kind regards, Olivier -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html The output is what I would expect to see (bar of height 1, overlaid with a bar of height -2, overlaid with a bar of height 3) so you only see the last bar.  What are you expecting to see?Tony Richardson  -- Olivier ThomannSenior ResearcherInnovation, Discovery and External CollaborationNeste CorporationTechnology Centre, KilpilahtiPOB 31006101 Porvoo, FinlandMobile +358 (0)40 338 0371www.neste.com This e-mail and any further e-mails from the Neste Corporation or any of its employees, directors or other representatives, including any file(s) transmitted with such messages ("message") may be confidential and intended solely for the entity or individual to whom it is addressed or to whom the sender intended to address it. If you are not the intended recipient of this or any following message, please contact the sender immediately upon receipt of the message and delete the message from your system without reproducing, distributing or retaining copies thereof or using or disclosing the information contained therein. Thank you.Due to the insecure nature of this medium, this or any following message may have been altered without the knowledge of sender. The sender will therefore not be liable for the message if modified.
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 On Mon, Apr 20, 2020 at 12:53 AM Olivier Thomann <[hidden email]> wrote:Dear Tony,Thank you for your answer. For what I know, usually stacked bar would look like this (same data in excel):The negative value block would be in the negative side and the positive value on the positive side, without overlap.Kind regards,OlivierOn Sun, 19 Apr 2020 at 17:26, Tony Richardson <[hidden email]> wrote:On Sun, Apr 19, 2020 at 9:05 AM Olive <[hidden email]> wrote:Hello, I am trying to plot a bar plot, stacked, containing positive and negative value. Unfortunately, I don't manage to get a good result with the bar function. The stacked bar plot works well with positive values.  z=[1 2 3  4 3 1]  h = bar (z, 'stacked'); And does not wok well with negative value. It seems the values are printed on top of each other.  figure  z=[1 -2 3  4 3 1]  h = bar (z, 'stacked'); Do you know a way to work around this? Kind regards, Olivier -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html The output is what I would expect to see (bar of height 1, overlaid with a bar of height -2, overlaid with a bar of height 3) so you only see the last bar.  What are you expecting to see?Tony Richardson  -- Olivier ThomannHi Olivier,Octave's stacked option appears to work differently than Excel.  I prefer Octave's behavior (although it would be considered a bugif it differs from MATLAB, I don't have MATLAB to check).   It appears that you can get the plot you want by plotting the positive and negative values separately:z=[1 -2 3;  4 3 1]zt = z;zt(zt<0) = 0h = bar (zt, 'stacked');hold onzt = z;zt(zt>0) = 0h = bar (zt, 'stacked');hold offTony
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 On Mon, Apr 20, 2020 at 7:23 AM Tony Richardson <[hidden email]> wrote:On Mon, Apr 20, 2020 at 12:53 AM Olivier Thomann <[hidden email]> wrote:Dear Tony,Thank you for your answer. For what I know, usually stacked bar would look like this (same data in excel):The negative value block would be in the negative side and the positive value on the positive side, without overlap.Kind regards,OlivierOn Sun, 19 Apr 2020 at 17:26, Tony Richardson <[hidden email]> wrote:On Sun, Apr 19, 2020 at 9:05 AM Olive <[hidden email]> wrote:Hello, I am trying to plot a bar plot, stacked, containing positive and negative value. Unfortunately, I don't manage to get a good result with the bar function. The stacked bar plot works well with positive values.  z=[1 2 3  4 3 1]  h = bar (z, 'stacked'); And does not wok well with negative value. It seems the values are printed on top of each other.  figure  z=[1 -2 3  4 3 1]  h = bar (z, 'stacked'); Do you know a way to work around this? Kind regards, Olivier -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html The output is what I would expect to see (bar of height 1, overlaid with a bar of height -2, overlaid with a bar of height 3) so you only see the last bar.  What are you expecting to see?Tony Richardson  -- Olivier ThomannHi Olivier,Octave's stacked option appears to work differently than Excel.  I prefer Octave's behavior (although it would be considered a bugif it differs from MATLAB, I don't have MATLAB to check).   It appears that you can get the plot you want by plotting the positive and negative values separately:z=[1 -2 3;  4 3 1]zt = z;zt(zt<0) = 0h = bar (zt, 'stacked');hold onzt = z;zt(zt>0) = 0h = bar (zt, 'stacked');hold offTonyFYI.  Octave's behavior is consistent with MATLAB's,Tony
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Administrator In reply to this post by Tony Richardson-4 Octave's stacked option appears to work differently than Excel.  I prefer Octave's behavior (although it would be considered a bugif it differs from MATLAB, I don't have MATLAB to check).   Confirming that Octave's behavior is not matlab compatible.  running both Olivier's and Tony's code in both octave 5.2.0 and Matlab 2020a, tony's code looks identical in each (except for colormap), Olivier's code in Matlab looks identical to Tony's (except the negative part is a different color), while Olivier's code in Octave has the negative bar overlapping the rest of the chart.should probably be captured in a compatibility bug report. If a search doesn't turn up an existing one I'll file one with all of the images for comparison.
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Administrator should probably be captured in a compatibility bug report. If a search doesn't turn up an existing one I'll file one with all of the images for comparison.bug 58216 submitted
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Administrator In reply to this post by Tony Richardson-4 Hi Olivier,Octave's stacked option appears to work differently than Excel.  I prefer Octave's behavior (although it would be considered a bugif it differs from MATLAB, I don't have MATLAB to check).   It appears that you can get the plot you want by plotting the positive and negative values separately:z=[1 -2 3;  4 3 1]zt = z;zt(zt<0) = 0h = bar (zt, 'stacked');hold onzt = z;zt(zt>0) = 0h = bar (zt, 'stacked');hold offTonyFYI.  Octave's behavior is consistent with MATLAB's,Tony  only for your code.  his original code does produce different results in Matlab and Octave.
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 In reply to this post by nrjank Ahh, I compared against MATLAB 2018a in which Octave and MATLAB produced similar graphs for all code..TonyOn Mon, Apr 20, 2020 at 11:18 AM Nicholas Jankowski <[hidden email]> wrote:should probably be captured in a compatibility bug report. If a search doesn't turn up an existing one I'll file one with all of the images for comparison.bug 58216 submitted
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 In reply to this post by nrjank On Mon, Apr 20, 2020 at 11:50 AM Nicholas Jankowski <[hidden email]> wrote:Hi Olivier,Octave's stacked option appears to work differently than Excel.  I prefer Octave's behavior (although it would be considered a bugif it differs from MATLAB, I don't have MATLAB to check).   It appears that you can get the plot you want by plotting the positive and negative values separately:z=[1 -2 3;  4 3 1]zt = z;zt(zt<0) = 0h = bar (zt, 'stacked');hold onzt = z;zt(zt>0) = 0h = bar (zt, 'stacked');hold offTonyFYI.  Octave's behavior is consistent with MATLAB's,Tony  only for your code.  his original code does produce different results in Matlab and Octave. Apparently this was a change introduced in MATLAB 2019b, quoting from the release notes:"Stacked groups of bars display negative bars below zero, rather than overlapping the bars."Tony
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Administrator Apparently this was a change introduced in MATLAB 2019b, quoting from the release notes:"Stacked groups of bars display negative bars below zero, rather than overlapping the bars."good catch. missed that.
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 Administrator On Mon, Apr 20, 2020 at 1:02 PM Nicholas Jankowski <[hidden email]> wrote:Apparently this was a change introduced in MATLAB 2019b, quoting from the release notes:"Stacked groups of bars display negative bars below zero, rather than overlapping the bars."good catch. missed that.Actually, where is that? I see numerous references to it on the Matlab 2019b release notes in the Graphics section, but it's not there (anymore?).  it is in the current function help, though.
Open this post in threaded view
|

## Re: Stacked bar plot with positive and negative values

 On Mon, Apr 20, 2020 at 12:10 PM Nicholas Jankowski <[hidden email]> wrote:On Mon, Apr 20, 2020 at 1:02 PM Nicholas Jankowski <[hidden email]> wrote:Apparently this was a change introduced in MATLAB 2019b, quoting from the release notes:"Stacked groups of bars display negative bars below zero, rather than overlapping the bars."good catch. missed that.Actually, where is that? I see numerous references to it on the Matlab 2019b release notes in the Graphics section, but it's not there (anymore?).  it is in the current function help, though. https://www.mathworks.com/help/matlab/release-notes.html look under R2019b then Graphics then expand the "Bar Charts" entry.Tony