Matlab中的自定义轴刻度 [英] custom axis scale in matlab

查看:208
本文介绍了Matlab中的自定义轴刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来获得绘图轴上的自定义缩放比例?

Is there a simple way to obtain customized scaling on the plot axis?

例如,符号功能提供{x,log10(y)}缩放比例,以便人们可以自动放大/放大,并且刻度和标签会自动调整.我想对{x,asinh(2 * y)}缩放也有同样的看法.解决方案:

e.g., the semilogy function provides {x, log10(y)} scaling such that one can automatically zoom in/ot and ticks and labels automatically adjust. I would like to have the same thing with the {x, asinh(2*y)} scaling. the solution:

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

适用于静态"绘图,但是我希望有刻度-缩放时可以自动调整标签...

works for a "static" plot but I would like to have the ticks - label to autoadjust when zooming...

推荐答案

此处是您感兴趣的功能.每次放大/缩小时,都会缩放Y轴.使用了"sinh"变换,但可以是任何变换.

Here is the function of interest. It will scale the Y-Axis each time you zoom in/out. 'sinh' transform is used, but it could be any transform.

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

The matlab core function behind it is 'ActionPostCallback'. See http://www.mathworks.fr/fr/help/matlab/ref/zoom.html for details. The analogue function 'ActionPreCallback' could be used too. These little handy functions can also be used for the main functions 'rotate3d', 'pan', 'zoom' and '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中的自定义轴刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆