Matlab中的自定义坐标轴刻度

4

有没有一种简单的方法来获得自定义缩放的绘图轴?

例如,semilogy函数提供{x,log10(y)}缩放,使得可以自动缩放和刻度线和标签自动调整。我希望使用{x,asinh(2 * y)}缩放来实现同样的效果。解决方案:

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

这段代码适用于“静态”图,但我希望在缩放时刻度标签能够自动调整...


1
我相信你需要自己进行缩放,并应用自定义的刻度标记。 - MZimmerman6
1个回答

3
这里是需要关注的函数。每次缩放时,它都会调整Y轴比例。使用了'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'));  

听起来不错。我会尽快查看它。至于代码,我忘记了转置(即兴打的行)=),但'sinh'实际上是正确的(原始比例值通过缩放函数的反函数获得)。 - Davide
太好了 - 我已经删除了注释并将asinh / sinh更改回其原始状态。 - marsei

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接