# How to show an individual YTickLabel to the right of the single Y axis?

11 ビュー (過去 30 日間)
rai7aeLa 2018 年 5 月 29 日
コメント済み: Greg 2018 年 5 月 29 日

Hello,

I would like to place an YTickLabel to the right of the Y axis. Currently, my figure looks like this:

Now, I would like to move the lower label $-M_{r0}$ (which is overlapping with the graph) to the right of the Y axis. How can I achieve that? Thanks!

Here's my MWE:

close all;
set(groot, 'defaultAxesTickLabelInterpreter','latex');

figure1=figure('Position',[320 50 600 450]);
axes1=axes('Parent',figure1,'FontSize',14);
o=linspace(-5,5,1000);
M=sign(o).*(10+o.^2);
plot1=plot(o,M,'Parent',axes1,'LineWidth',2);
set(plot1,'Color',[1 0 0]);
ylabel('Torque $M_r(\omega)$','FontSize',14,'Interpreter','latex');
xlabel('Velocity $\omega$','FontSize',14,'Interpreter','latex');
title('');

set(gca,'xtick',[],'xticklabel',[]);
set(gca,'ytick',[-10,10],'yticklabel',{'\fontsize{14pt}{17pt}$-M_{r0}$','\fontsize{14pt}{17pt}$M_{r0}$'});
set(gca,'XAxisLocation','origin','YAxisLocation','origin');
axp=get(gca,'Position'); % needed to put arrows in the right position
annotation('arrow', [axp(1) axp(1)+axp(3)],[axp(2)+axp(4)/2 axp(2)+axp(4)/2]);
annotation('arrow', [axp(1)+axp(3)/2 axp(1)+axp(3)/2],[axp(2) axp(2)+axp(4)]);
box off;


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

### 採用された回答

Ameer Hamza 2018 年 5 月 29 日

Instead of using ylabel to write the labels, use annotation to place the labels at the required position. For example,
set(gca,'ytick',[],'yticklabel',[]); % remove the yticks
annotation('textbox', 'String', '\fontsize{14pt} -M_{r0}', 'Position', [0.5, 0.4 0.1 0.1], 'EdgeColor', [1 1 1])
annotation('textbox', 'String', '\fontsize{14pt} M_{r0}', 'Position', [0.5, 0.6 0.1 0.1], 'EdgeColor', [1 1 1])
You might need to experiment with the position property to get the desired position.
Edit: To keep the location of labels linked with your graph values, use the following statements
text('String', '\fontsize{14pt} -M_{r0}', 'Position', [1 -3])
text('String', '\fontsize{14pt} M_{r0}', 'Position', [1 3])
Here Position property specifies the x and y data value on the graph, not the normalized coordinates (0 to 1) as required by annotation(). So if the axis limit change, these labels will also change accordingly.
##### 7 件のコメント表示非表示 6 件の古いコメント
Ameer Hamza 2018 年 5 月 29 日
You are welcome.

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

### その他の回答 (1 件)

Greg 2018 年 5 月 29 日

It isn't elegant, but space pad the tick label until it shows up better.
##### 2 件のコメント表示非表示 1 件の古いコメント
Greg 2018 年 5 月 29 日
Yes, it is right justified to the Y axis. You'd had to right-pad until the text moves to the left.

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

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by