八度图中 x 轴的最小步长?

问题描述 投票:0回答:1

上下文

使用 Octave 7.1.0(与 8.2.0 的结果相同),我想使用

pcolor()
在密度图上绘制,使用
bar()
函数绘制条形图。然后我希望轴的范围从我的代码中预先计算的值开始。当这个数字第一次出现时,两个图都有右轴。 然而,当我放大或重新缩放整个图形时,原来的轴缩放丢失了。我能够将问题定位到我的 x 向量的步长。

问题

您可以通过运行此代码并注释/取消注释

t
向量的定义来体验相同的行为。

clc
clear all
close all

n = 200;
bins = peaks(n);
t = [0:1e-11:(n-1)*1e-11];  % This vector creates the bug
%t = [0:1e-10:(n-1)*1e-10];  % This vector works
timeAxis = [t(50) t(end-50)];

figure
plot(t, bins(:,50))
axis manual
xlim(timeAxis)
hold off

这里是用户将人物全屏前后的剧情图。 Octave 不会抛出任何警告/错误。

在使用

t = [0:1e-11:(n-1)*1e-11]
时,如何确保用户全屏图形后轴缩放保持不变?

octave matlab-figure axis
1个回答
1
投票

所以我找到了解决这个问题的方法,只需将 x 向量 (

t
) 乘以小于原始步长的最接近的 1000 次幂(1e3、1e6、1e9 等)。

clc
clear all
close all

n = 200;
bins = peaks(n);

% From the original step size, find the closest 1e3 factor
tstep = 1e-11;
factor = floor(abs(log10(tstep)/3));
factor = 10^(3*factor);

t = [0:tstep:(n-1)*tstep];
timeAxis = [t(50) t(end-50)];

figure
% Original
subplot(1,2,1)
hold on
title('Original Bug')
plot(t, bins(:,50))
xlim(timeAxis)
xlabel('Time (s)')
hold off
% Work around with factor multiplication
subplot(1,2,2)
hold on
title('Work around')
plot(t.*factor, bins(:,50))
xlim(timeAxis.*factor)
xlabel(['Time (1e-', num2str(log10(factor)), ' s)'])
hold off
© www.soinside.com 2019 - 2024. All rights reserved.