How to move the Yaxis exponent outside
17 次查看(过去 30 天)
显示 更早的评论
I would like to move the exponent of the Y axis that is naturally above the figure, to the outside (left side) of the figure.
See my impressive plot attached. Any suggestion (I mean with an automatic way) such as 'TickDir' 'out' for the ticks, but for the exponent x10^6 here. Cheers
0 个评论
采纳的回答
Voss
2024-2-19
I don't know of a way to move that exponent label, but if you have R2023b or later, you can use the ysecondarylabel function to set its string to empty, and then create your own exponent label (using the text function) where you want.
plot(1e6:1e6:7e6)
ylim([1e6 7.5e6])
ax = gca();
ysecondarylabel(ax,'')
text(ax, ...
'String','x10^{6}', ...
'Units','normalized', ...
'Position',[0 1], ...
'HorizontalAlignment','right', ...
'VerticalAlignment','bottom')
4 个评论
Sim
2024-5-30
编辑:Sim
2024-5-30
>> version
ans =
'23.2.0.2515942 (R2023b) Update 7'
and with your solution
plot(1e6:1e6:7e6)
ylim([1e6 7.5e6])
ax = gca();
ysecondarylabel(ax,'')
text(ax, ...
'String','x10^{6}', ...
'Units','normalized', ...
'Position',[0 1], ...
'HorizontalAlignment','right', ...
'VerticalAlignment','bottom')
I get the following warning/error:
String scalar or character vector must have valid interpreter syntax:
x10^{6}
and the following plot:
What can I do to get your result?
Voss
2024-5-30
It seems like you may have set the default text interpreter to latex instead of tex. Try explicitly specifying tex as the interpreter for this text object:
text(ax, ...
'Interpreter','tex', ...
'String','x10^6', ... {} optional in this case
'Units','normalized', ...
'Position',[0 1], ...
'HorizontalAlignment','right', ...
'VerticalAlignment','bottom')
更多回答(1 个)
Sulaymon Eshkabilov
2024-2-19
Here is one example how to get it done:
% Sample data for plot display
x = linspace(0, 2*pi, 100);
y = 1e6 * sin(x);
%% Demo 1
figure;
plot(x, y);
yticks([0, max(y)])
yticklabels({'0', '10^6'});
ylabel('Y-axis');
title('Example Plot');
xlabel('X-axis');
%% Demo 2
figure;
plot(x, y);
yticks([min(y), 0, max(y)])
yticklabels( {'-10^6', '0', '10^6'});
ylabel('Y-axis');
title('Example Plot');
xlabel('X-axis');
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!