Axis labels - subscripts not working

79 次查看(过去 30 天)
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.

采纳的回答

dpb
dpb 2021-11-29
编辑:dpb 2021-11-29
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 个评论
Andrei
Andrei 2023-5-13
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 2023-5-13
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.

请先登录,再进行评论。

更多回答(1 个)

Cris LaPierre
Cris LaPierre 2021-12-22
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 个评论
dpb
dpb 2023-5-13
"...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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by