将 y 轴拆分为线性和对数刻度 matlab
splitting the y axis into a linear and logarithmic scale matlab
我想在绘制图形时将 y 轴分成线性和对数比例部分。例如,1-30 为线性刻度,30-100 为对数刻度。有什么办法吗?谢谢
不知道有没有直接的方法。但是,您可以手动加入两个区域(线性和对数)。见附件代码:
clc; clear;
x = 1:100; % Values to plot
xorg = 0:10:100; % Ticks on the Y-axis
xticks = xorg; % Final tick location
x1 = log10(30); % start of logarithmic scale
x2 = log10(100); % end of logarithmic scale
dx = (x2-x1)*60; % 60 here is an arbitrary scaling factor
scale = @(x)(log10(x)-x1)/(x2-x1)*dx+30; % Scaling from lin to log
x(x>30) = scale(x(x>30)); % Apply scaling to plotting values
xticks(xticks>30) = scale(xticks(xticks>30)); % Apply scaling to Y ticks
plot(x);
ylim([0 max(xticks)]);
set(gca,'YTick',xticks,'YTickLabel',xorg); % Update the ticks
这会产生如下图。
我想在绘制图形时将 y 轴分成线性和对数比例部分。例如,1-30 为线性刻度,30-100 为对数刻度。有什么办法吗?谢谢
不知道有没有直接的方法。但是,您可以手动加入两个区域(线性和对数)。见附件代码:
clc; clear;
x = 1:100; % Values to plot
xorg = 0:10:100; % Ticks on the Y-axis
xticks = xorg; % Final tick location
x1 = log10(30); % start of logarithmic scale
x2 = log10(100); % end of logarithmic scale
dx = (x2-x1)*60; % 60 here is an arbitrary scaling factor
scale = @(x)(log10(x)-x1)/(x2-x1)*dx+30; % Scaling from lin to log
x(x>30) = scale(x(x>30)); % Apply scaling to plotting values
xticks(xticks>30) = scale(xticks(xticks>30)); % Apply scaling to Y ticks
plot(x);
ylim([0 max(xticks)]);
set(gca,'YTick',xticks,'YTickLabel',xorg); % Update the ticks
这会产生如下图。