使用实际数据作为标签,但使用log10缩放绘制的数据.
% data
x = -3:0.1:3;
y = sign(x).*10.^abs(x);
% scaling function
scale = @(x) sign(x).*log10(abs(x));
N = 7; % number of ticks desired
% picking of adequate values for the labels
TickMask = linspace(1,numel(y),N);
YTickLabels = y(TickMask);
% scale labels and plotdata, remove NaN ->inconsistency, do you really want that?
YTick = scale( YTickLabels );
Y = scale(y);
YTick(isnan(YTick)) = 0;
Y(isnan(Y)) = 0;
% plot
plot(x,Y)
set(gca,'YTick',YTick,'YTickLabels',YTickLabels)
grid on
对于N = 7:
对于N = 11
如何找到N的有效值?
以下函数(thanks to gnovice)将返回您可以为N选择的所有可能值:
n = numel(x);
N = find(rem(n./(1:n), 1) == 0) + 1;
关于半成品风格的标签:通过在情节之前添加以下行:
YTickLabels = cellfun(@(x) ['10^' num2str(x)], num2cell(YTick),'UniformOutput',false)
你至少可以达到这样的目的:
不漂亮而不通用,但是一个好的开始.