How do you remove the exponent from all y-axes on a stackploted figure?

3 vues (au cours des 30 derniers jours)
Brianna Miranda
Brianna Miranda le 16 Fév 2023
Modifié(e) : dpb le 17 Fév 2023
I am trying to change my y-axes so that each one is a decimal instead of #x10^-4. How can I make this change for a stackedplot?

Réponse acceptée

dpb
dpb le 16 Fév 2023
Déplacé(e) : dpb le 16 Fév 2023
Some things aren't possible; that's one....see the discussion about what a stackedplot object is in the doc --
s=StackedLineChart object, which is a standalone visualization. Use s to set properties on the stacked plot after creating it.
...
Standalone Visualization
A standalone visualization is a chart designed for a special purpose that works independently from other charts. Unlike other charts such as plot and surf, a standalone visualization has a preconfigured axes object built into it, and some customizations are not available. ...
Unfortunately, the exposed properties (as you've undobtedly discovered) don't include those pieces of the axes object; the axes has been neutered drastically as to what you can get a handle to, and thereby change.

Plus de réponses (1)

dpb
dpb le 16 Fév 2023
Modifié(e) : dpb le 17 Fév 2023
Actually, the above isn't true; it turns out you CAN get to the underlying axes objects and they are still "plain, ordinary axes".
I thought I had looked at this before but apparently my recollections were flawed. Try...ohhhh--now, I remember why I had the recollection, even findall won't return the axes from the standalone visualization that it will with hidden handles of regular plots. I don't have time to dig into that at the moment, but the following will work...
hS=stackedplot(....);
hAx=findobj(hS.NodeChildren,'Type','axes'); % find the axes handles that are hidden under NodeChildren
for h=hAx.' % iterate over the collection/array
try % don't crash for a nonnumeric y axes handle
h.YAxis.Exponent=0; % set exponent
h.YAxis.TickLabelFormat='%.0f'; % and to %f format (default is %g)
catch % keep on going if errors on one or more...
end
end
Address the individual axes with the subscripting to the axes array.
NOTA BENE: The above will only provide satisfactory results for exponents >0; more subtle logic will be needed to handle general case well.

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by