Axis labels - subscripts not working

80 views (last 30 days)
Wiktor Wróblewski
Wiktor Wróblewski on 29 Nov 2021
Commented: dpb on 13 May 2023
Morning all,
could you please help me with subscripts in axis labels?
When I use code:
figure(1);
title('Generation change')
xlabel('Time [sec]')
ylabel('ΔP_G [pu]')
legend('ΔP_G for 1%','ΔP_G for 5% ','Location','southeast');
Everything is working.
However, when I use "plot" command, subsrcipt on y axis is not working anymore:
figure(1);
plot(PT1);
hold on;
plot(PT2);
grid on;
title('Generation change')
xlabel('Time [sec]')
ylabel('ΔP_G [pu]')
legend('ΔP_G for 1%','ΔP_G for 5% ','Location','southeast');
Data I am using is timeseries from Simulink. Subscripts in legend are working in both cases. Thanks in advance.

Accepted Answer

dpb
dpb on 29 Nov 2021
Edited: dpb on 29 Nov 2021
What does
hAx=gca;hAx.YLabel.Interpreter
return after the figure?
If you get no error message, the above symptoms indicate that the label 'Interpreter' property is somehow set to default to 'none'.
If it were 'tex', the string would be interpreted as desired, it it were 'latex' it would generate an error about invalid interpreter syntax.
ADDENDUM
Given the additional info from the series of comments below, the workaround to your problem seemingly caused by Simulink being overly aggressive in its setting of MATLAB default graphics parameters is to use the explicit named parameter when calling x/ylabel
ylabel('ΔP_G [pu]','Interpreter','tex')
etc., SHOULD do it. If, for some reason, the instantiation of ylabel that is being calls ignores the named parameter (if it does, I'd also call that a bug and report it), then you can always revert to forcing it after the fact...
hYLbl=ylabel('ΔP_G [pu]'); % write label, save handle accept default interpreter
hYLbl.Interpreter='tex'; % now brute-force it to be wanted 'tex'
Changing the interpreter property for the object itself will change the behavior of the object; setting the default property after the fact won't; the object is already in existence and the default behavior is only looked at on object creation.
That's why the set options above didn't work -- I didn't think of the behavior actually being embedded in the function calls themselves; that's just so egregious I didn't think any chance TMW would have done -- I presumed it had gotten set once by accident and fixing it once would fix it forever.
  12 Comments
Andrei
Andrei on 13 May 2023
Hi, I am currently having the same problem, and when I try to reset it to factory settings, I get the following
set(groot,'factoryAxesTickLabelInterpreter','tex')
Error:
Error using matlab.ui.Root/set
Factory properties can only be queried, not set.
What should I do?
dpb
dpb on 13 May 2023
You don't set factory settings/or the root object as noted; you instead clear temporary and/or personal settings to restore the factory default programmtically. You should also be able to reset with the Preferences menu item, the problem will be if this is still the behavior with a time series, it'll destroy it again next time you plot one.
I had never found the timeseris object to be of much, if any, help; it always seemed to have some undesired behavior or lacked the ability to do something I wanted to do so I gave it up (or, actually, never adopted it as being of value) so hadn't discovered this aberrant behavior.
I would just use a timetable instead or just treat as regular double arrays to avoid the grief.

Sign in to comment.

More Answers (1)

Cris LaPierre
Cris LaPierre on 22 Dec 2021
I heard back. This was an intentional setting change introduced with Timeseries. The work around for now is to manually override the axis label interpreter setting:
PT1 = timeseries(rand(5,1));
PT2 = timeseries(rand(5,1));
figure(2)
plot(PT1)
hold on
plot(PT2)
hold off
grid on
title('Generation change')
xlabel('Time [sec]')
ylabel('ΔP_G [pu]')
legend('ΔP_G for 1%','ΔP_G for 5% ','Location','southeast')
% set YLabel interpreter back to 'tex'
ax = gca;
ax.YLabel.Interpreter = 'tex';
  1 Comment
dpb
dpb on 13 May 2023
"...This was an intentional setting change introduced with Timeseries.:"
Just saw the latest plea from the wilderness and this follow-up, @Cris LaPierre. Why on earth would anybody choose to have done this dastardly deed? I can see no justification could possibly be to have done.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!