问题
Is there a simple way to obtain customized scaling on the plot axis?
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...
回答1:
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.
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'));
来源:https://stackoverflow.com/questions/17676225/custom-axis-scale-in-matlab