two stacked y labels on one single y axis

14 Ansichten (letzte 30 Tage)
Lloyd Sullivan
Lloyd Sullivan am 27 Jul. 2018
Kommentiert: Star Strider am 27 Jul. 2018
Hi,
I am trying to recreate the above graph. However, I cannot get the two ylabels in the correct places. I'd rather not do it manually using the figure editor, but if there is no other option, then i will.
figure
xlim([80 140])
ylim([-0.1 1.4])
ylabel('$\displaystyle\frac{f_v}{f_n}$','interpreter','latex')
% This is the second y label
% ylabel('$\displaystyle\frac{Y}{D}$','interpreter','latex')
xlabel('\it{Re}','interpreter','latex')
ylh = get(gca,'ylabel');
ylp = get(ylh, 'Position');
set(ylh, 'Rotation',0, 'Position',ylp, 'VerticalAlignment','middle',...
'HorizontalAlignment','right')
Any help would be greatly appreciated.
Best regards,
Lloyd

Akzeptierte Antwort

Star Strider
Star Strider am 27 Jul. 2018
Bearbeitet: Star Strider am 27 Jul. 2018
Insert some empty values between the two LaTeX strings to create spaces (this works with cell arrays):
ytxt = {'$\displaystyle\frac{f_v}{f_n}$';[];[];[];[];[];[];[];[];[];[];'$\displaystyle\frac{Y}{D}$'};
ylabel(ytxt,'interpreter','latex')
Experiment to get the result you want.
EDIT A somewhat more efficient version that produces the same result (in R2018a):
ytxt = {'$\displaystyle\frac{f_v}{f_n}$';char(repmat(' ',10,1));'$\displaystyle\frac{Y}{D}$'};
Vary the number of spaces (here 10) in the repmat call to produce the result you want. It must always be a column vector.
  2 Kommentare
Lloyd Sullivan
Lloyd Sullivan am 27 Jul. 2018
Works perfectly! Thank you Star Strider and thanks for all the speedy responses everyone.
Star Strider
Star Strider am 27 Jul. 2018
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by