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 日

2 投票

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 件のコメント

Wiktor Wróblewski
Wiktor Wróblewski 2021 年 11 月 29 日
It returns 'none'. I have changed interpreter in property inspector to "tex" and it is working. Thanks. However, what should I code to make it work automatically, so I do not have to change it manually every time figure is printed?
dpb
dpb 2021 年 11 月 29 日
Oh. Had intended to point out ..
set(groot,'factoryAxesTickLabelInterpreter','tex')
will restore the factory setting of the TeX interpreter.
To restore all settings to their factory defaults, use
set(groot,'factory')
The latter will lose any customizations purposely made if you have any, but will restore all back to install settings if there have been accidental changes or an imported toolset was rude enough to have changed default values at the root level.
Wiktor Wróblewski
Wiktor Wróblewski 2021 年 11 月 29 日
Thank you very much for your help. In my opinion, it seems that plotting timeseries from Simulink is changing the interpreter, because if labels are not specified by user, figure is printed with default labels. "Data" on y and "Time (seconds)" on x. Perhaps, these default labels interpreter is set to 'none'. If I plot data "created in matlab" interpreter default setting is 'tex' as it should be.
dpb
dpb 2021 年 11 月 29 日
編集済み: dpb 2021 年 11 月 29 日
I don't have Simulink so can't say...
If you reset the default property at groot and then rerun the Simulink plot, does it then get reset to 'none'? iI that is so I'd consider it an implementation foopah/bug and submit a bug report about the behavior.
Out of curiosity, if it does make that setting change, is it persistent? That is, if you exit MATLAB and restart, is it still now 'none' or does it then revert to the default? If the former, it's definitely a bug.
I'd have to think a lot more about the various places at which the default properties can be set about ways in which it would/could happen as described if isn't persistent.
Setting default values has so many nuances I've never got it all completely straight as to what stays where and when...
Wiktor Wróblewski
Wiktor Wróblewski 2021 年 11 月 29 日
Yes, everytime I plot Simulink data interpreter resets to 'none'. Restarting MATLAB does not change it.
As I mentioned before, I think it is caused by this default labels. I suppose their interpreter is defined in MATLAB code as 'none'. Commands xlabel() or ylabel() change only text, not the interpreter, so I have to change the interpreter manually everytime I print figure. "Set" commands you suggested me using do not work, no matter where I put them in the code (before "plot" or after). My default setting of label interpreter is definitely 'tex'. Not sure if this is a bug or MATLAB developers wanted to define interpreter of this default labels as 'none' for some reason.
Attached figure code is only:
figure(1);
plot(f1);
hold on;
plot(f2);
grid on;
Where f1 and f2 are timeseries data from Simulink.
dpb
dpb 2021 年 11 月 29 日
編集済み: dpb 2021 年 11 月 29 日
If I were a MATLAB user with Simulink, I'd definitely regard Simulink changing my MATLAB default settings behind my back as a bug. To modify the groot value is egregious because, as you've discovered, that changes everything that happens from that point forward.
There are ways for Simulink to force that behavior on its plots only by setting the property at the figure or axes level instead of root; not having done it that way is the reason I would definitely consider the present behavior you describe as a bug. It is, at least, "rude" in the extreme, even if TMW were to claim WAD ("working as designed", one of the favorite outs of developers when they don't want to admit to/fix a nonfatal bug).
Anyways, to work around it given that it appears that the version of legend that gets invoked if you use Simulink-generated data which triggers a specific axes format automagically will be to set the 'Interpreter' property specifically when you use x/ylabel since the behavior seems to be buried inside them.
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, know interpreter may be 'none'
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.
Wiktor Wróblewski
Wiktor Wróblewski 2021 年 11 月 30 日
ylabel('ΔP_G [pu]','Interpreter','tex')
This command worked. Thank you very much for your help and for an interesting conversation. Taking your explanations into consideration I will submit a bug report about that behaviour.
dpb
dpb 2021 年 11 月 30 日
I don't understand why Simulink would care about the user default label interpreter -- doesn't make any sense that it would not let the user use whatever he pleases.
dpb
dpb 2021 年 11 月 30 日
編集済み: dpb 2021 年 11 月 30 日
OBTW, even though the above will mask the symptoms, if indeed the value in groot is being reset, that's going to have ramifications all over the rest of MATLAB because the above won't reset it back to the default 'tex' value; you'll still have to execute the set code every stinkin' time you plot one of those time traces.
As noted, this behavior is "just plain rude!" and I can't believe it hasn't been observed before, unless it's a brand new behavior.
What does
whos f1
where f1 is one of these timeseries variables return? Is it a unique class or a struct or something, not just an array of double? That would also indicate Simulink has its own plot.
How about
which -all plot
return? I've never seen a Simulink installation so don't know if it produces a specific legend function that is getting called based on the object type of the time series data or if it might be somewhere else more deeply buried in the bowels.
I rarely, if ever, suggest munging on a TMW file, but this is a case I might go spelunking and see if I could find the culprit code line and neuter it.
For confirmation, try the following and post the result...
get(groot,'factoryAxesTickLabel')
figure
plot(randn(10,1))
hAx=gca;
hAx.TickLabelInterpreter
hold on
plot(f1)
hAx.TickLabelInterpreter
Cris LaPierre
Cris LaPierre 2021 年 12 月 21 日
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.
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 日

2 投票

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.

サインインしてコメントする。

カテゴリ

製品

リリース

R2021b

質問済み:

2021 年 11 月 29 日

コメント済み:

dpb
2023 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by