Axis labels - subscripts not working

12 views (last 30 days)
Wiktor Wróblewski
Wiktor Wróblewski on 29 Nov 2021
Answered: Cris LaPierre on 22 Dec 2021
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.
  10 Comments
Cris LaPierre
Cris LaPierre on 21 Dec 2021
FWIW, it does not appear to matter if the timeseries is created in Simulink or not. It happens if I try to plot a timeseries created in MATLAB, too.
%Works
figure(1)
plot(rand(5,1))
hold on
plot(rand(5,1))
hold off
title('Generation change')
xlabel('Time [sec]')
ylabel('ΔP_G [pu]')
legend('ΔP_G for 1%','ΔP_G for 5% ','Location','southeast')
% Interpreter ignored
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')
get(groot,'factoryAxesTickLabel')
ans = 'tex'
I will report this behavior.

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';

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!