Stacked bar plot for negative ambient .

I have the components simulation data at -30C and steady bias , maneuver rise and margin (calculeted from given Tmax of each compoenent) to be plotted in stacked bar format ,
in the positive ambient the plots works fine but in negative ambient , the steady bias is starting from 0 (lets say @-30C , component setad bais is 6C , then it should start from -24C ?. see attched image .
please suggest the better ways to handle .
Thank you .

2 commentaires

Chuguang Pan
Chuguang Pan le 13 Août 2025
bar function with BaseValue option may be effective
dpb
dpb le 13 Août 2025
@Anil it would be helpful to have the data
If the baseline for each bar is the same, then the suggestion of @Chuguang Pan should work for you straightforwardly.
But, the 'BaseValue' is one value for the whole plot, not on a bar-by-bar basis, so in that case you may have to get creative and either draw each bar individually with its own baseline value (I've not ever tried this) or rescale the data to be positive and then manually set the axes tick values to the desired values.
If the latter is the case, it would be most helpful to have the data and a more complete description of just how you would want the plot to look.

Connectez-vous pour commenter.

Réponses (1)

Cris LaPierre
Cris LaPierre le 13 Août 2025
Déplacé(e) : Cris LaPierre le 16 Août 2025
It would be helpful to see the code you used to create the plot. It appears that Tamb has been set to -30, so when creating a stacked bar chart, the first level is the same for all bars - a bar that goes from -30 to 0.
Tamb = -30*ones(5,1);
Bias = randi(20,[5,1]);
Rise = randi(40,[5,1]);
Margin = randi(200,[5,1]);
bar([Tamb Bias Rise Margin],'stacked')
legend("Tamb","Steady Bias","Maneuver Rise","Margin")
ylabel('Temperature')
Not exacty sure what you want, but using a bar to indicate Tamb doesn't seem right. Setting the BaseValue doesn't quite do what I would expect. Here's what I could come up with.
Tamb = -30;
bar([Bias Rise Margin],'stacked')
legend("Steady Bias","Maneuver Rise","Margin")
ylabel('Temperature')
yticklabels(Tamb+yticks)

3 commentaires

dpb
dpb le 16 Août 2025
Modifié(e) : dpb le 19 Août 2025
@Cris LaPierre, you're on to my way of thinking about what @Anil was wanting...just was not positive understood what the data actually represented...about whether this was a global reference.
Stacked bars with negative values with or without nonzero base values can be very confusing in their behavior/appearance. An attempt to draw double-sided confidence intervals here in the forum some time back was fraught with similar difficulties.
I don't have an out-of-the-box ready substitute, but I've complained/whined for years that bar is and has always been a problem child.
Cris LaPierre
Cris LaPierre le 16 Août 2025
@Adam Danz any thoughts on this one?
Adam Danz
Adam Danz le 3 Nov 2025
Just catching up here. The OP's goal and problem isn't clear to me -- I wonder if Cris' solution solved it.

Connectez-vous pour commenter.

Question posée :

le 13 Août 2025

Commenté :

le 3 Nov 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by