在图中重新缩放 Y 轴

Rescaling Y axis in a plot

我正在尝试调整 y 轴并将其更改为 [0 2.5] 并表明它必须乘以 1000 倍。

显然用 ylim=([0 25]) 设置限制是行不通的,我找不到办法做到这一点。

用于绘图:

AveTime = 1.0e+03 * [0.0020, 0.0291, 0.1279, 0.3061, 2.0599];
STDtime = [0.0519, 0.0117, 0.0166, 0.0071, 0.0165];
errorbar([10,25,50,75,100], AveTime, STDtime);

这是一个解决方法:
获取 YTick,将它们除以 1000 并设置为 YTickLabel.

set(gca,'YTickLabel',get(gca,'YTick')/1000);

在 MATLAB R2014b 或更高版本中,您还可以使用:

ax=gca;
ax.YTickLabel= ax.YTick/1000;

不利的一面是,正如评论中Hoki所提到的,

This is good but only for the final rendering of the figure (if you just want to look/print it). Once you override the YTickLabel, their mode change from auto to manual and any zoom/pan or modification of the axis limit will keep the existing tick labels which may be obsolete after the figure modification.

我相信这就是您所需要的,它应该适用于 >= 2014b 的 Matlab 版本:

ax = gca;
ax.YAxis.Exponent = 3;

这是一个代码示例:

clear;
close all;
clc;

x=1:10:1000;
y=3*x;
plot(x,y);
ax = gca;
ax.YAxis.Exponent = 3;

剧情: