gpt4 book ai didi

matlab - matlab中的自定义 Axis 刻度

转载 作者:太空宇宙 更新时间:2023-11-03 20:02:22 28 4
gpt4 key购买 nike

有没有一种简单的方法可以在绘图 Axis 上获得自定义缩放比例?

例如,semilogy 函数提供 {x, log10(y)} 缩放比例,这样就可以自动放大/缩小并自动调整刻度和标签。我想对 {x, asinh(2*y)} 缩放进行同样的操作。解决方案:

plot (x, asinh (2*y));
set (gca, 'YTickLabel', num2str (sinh (get (gca, 'YTick')(:)) / 2, '%g'))

适用于“静态”图,但我希望刻度 - 标签在缩放时自动调整...

最佳答案

这是感兴趣的函数。每次放大/缩小时它都会缩放 Y Axis 。使用“sinh”变换,但它可以是任何变换。

其背后的matlab核心函数是'ActionPostCallback'。参见 http://www.mathworks.fr/fr/help/matlab/ref/zoom.html了解详情。也可以使用模拟函数“ActionPreCallback”。这些方便的小功能也可用于主要功能“rotate3d”、“pan”、“zoom”和“brush”。

function applyCustomScalingWhenZooming  

%some data
x=1:1/1000:100;
y=1:1/1000:100;

%figure
figure;
plot (x, asinh (2*y));
set (gca, 'YTickLabel', ...
num2str ((sinh (get (gca, 'YTick')) / 2)(:), '%g')); %initial format

%defines callback when zoom action
h = zoom; %define handle for 'zoom'
%action to be called right after zooming
set(h,'ActionPostCallback', {@mypostcallback});


function mypostcallback(obj,event_obj)
%format function
set (gca, 'YTickLabel', ...
num2str ((sinh (get (gca, 'YTick')) / 2)(:), '%g'));

关于matlab - matlab中的自定义 Axis 刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17676225/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com