two stacked y labels on one single y axis

13 vues (au cours des 30 derniers jours)
Lloyd Sullivan
Lloyd Sullivan le 27 Juil 2018
Commenté : Star Strider le 27 Juil 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

Réponse acceptée

Star Strider
Star Strider le 27 Juil 2018
Modifié(e) : Star Strider le 27 Juil 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 commentaires
Lloyd Sullivan
Lloyd Sullivan le 27 Juil 2018
Works perfectly! Thank you Star Strider and thanks for all the speedy responses everyone.
Star Strider
Star Strider le 27 Juil 2018
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by