MATLAB Answers

0

Subscript in stackedplot DisplayLabels

Asked by Sebastian Sprunck on 18 Jul 2019
Latest activity Edited by Adam Danz
on 1 Aug 2019
Hello everyone,
I'm trying to build a stacked plot with 3 graphs using Matlab 2018b's stackedplot-function. I'd like to write the corresponding DisplayLabels in TeX-style so that I can use subscripts, as can be done in regular plots without problem using e.g.
'T_{r}'
When I create a stackedplot using below code though, the labels are printed 'as is' instead of as a subscript:
s = stackedplot(f,If,'DisplayLabels',{'T_{r} = 50 ns','T_{r} = 20 ns','T_{r} = 10 ns'});
StackedPlot.PNG
I've tried accessing Interpreter-properties and even setting
set(0,'defaultTextInterpreter','latex');
but couldn't get it to work as intended.
Can anyone please tell me how to do that?
Best regards
Sebastian

  4 Comments

Show 1 older comment
It looks like the handles to those labels aren't officially available. All you would need to do is set the "Interpreter" to "tex" which is normally the default interpreter for text but must not be the case here. Even findall() couldn't locate those handles. Maybe digging through the code will lead to an undocumented method of getting those handles but I couldn't get them otherwise.
Of course you could ditch the function and make your own subplots with identical x axes.
Hmmm, I suspected something like that. Guess that's the curse of new functionalities ;)
Building my own subplot was my first attempt, but I'd like the x axis to only show at the bottom, as is the case in the stackedPlot variant. If I could get the labels to work as I want them, it would mean much "cleaner" code for my script.
Yeah, there are a few newer plotting functions that have a bunch of features on lockdown such as heatmap() and stackedplot(). I avoid using them which is unfortunate since they have some nice added features but when you can edit the basic, they become less useful.

Sign in to comment.

1 Answer

Answer by Yair Altman on 31 Jul 2019
 Accepted Answer

You can access the individual stacked-axes' properties via the hidden sub-property Axes of the stackedplot's AxesProperties property, and then modify the YLabel's Interpreter property to 'tex' or 'latex' (it's 'none' by default).
For example, to change the middle (2nd) YLabel:
s = stackedplot(...);
axesProps = struct(s.AxesProperties(2)); % using struct() is undocumented
axesProps.Axes.YLabel.Interpreter = 'tex';
Note that using struct() to access internal object properties is undocumented.

  2 Comments

+1; awesome.

Sign in to comment.