簡體   English   中英

matlab中的自定義軸刻度

[英]custom axis scale in matlab

有沒有一種簡單的方法可以在繪圖軸上獲得自定義縮放?

例如,半語功能提供{x,log10(y)}縮放,使得人們可以自動放大/縮放並且標簽和標簽自動調整。 我希望{x,asinh(2 * y)}縮放具有相同的功能。 解決方案:

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

適用於“靜態”情節,但我希望有標記 - 標記在縮放時自動調整...

這是感興趣的功能。 每次放大/縮小時,它都會縮放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'));  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM