How to show an individual YTickLabel to the right of the single Y axis?
13 次查看(过去 30 天)
显示 更早的评论
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;
0 个评论
采纳的回答
Ameer Hamza
2018-5-29
编辑: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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!