Subscript in stackedplot DisplayLabels

조회 수: 25 (최근 30일)
Sebastian Sprunck
Sebastian Sprunck 2019년 7월 18일
편집: Yair Altman 2024년 2월 13일
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
Sebastian Sprunck
Sebastian Sprunck 2019년 7월 30일
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.
Adam Danz
Adam Danz 2019년 7월 30일
편집: Adam Danz 2019년 7월 30일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Yair Altman
Yair Altman 2019년 7월 31일
편집: Yair Altman 2024년 2월 13일
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(...);
drawnow % ensure that the plot is updated before proceeding
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.
  댓글 수: 6
Ron
Ron 2024년 2월 4일
편집: Ron 2024년 2월 4일
Thankyou for responsding sir but I did try but it didnt do anything except the warning.
or there is something wrong with my code??
ss=stackedplot(error,'LineWidth',1.5);
ss.DisplayLabels = [sample_name,sample_name(1)+"_{abc}"];
axesProps = struct(ss.AxesProperties(4)); % using struct() is undocumented
axesProps.Axes.YLabel.Interpreter = 'tex';
Adam Danz
Adam Danz 2024년 2월 13일
The call to struct in this context is undocumented. It needs to be called after the stackplot is generated. This can be done by adding a drawnow before calling struct.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by