Custom axis scale in matlab

Is there a simple way to get individual scaling on the axis of the graph?

for example, the semilogy function scales {x, log10 (y)} so that / ot can be increased automatically, and ticks and tags are automatically adjusted. I would like to have the same with scaling {x, asinh (2 * y)}. decision:

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

works for a β€œstatic” plot, but I would like ticks shortcuts to automatically adjust when scaling ...

+4
source share
1 answer

Here is the function of interest. It scales the Y axis with each increase / decrease. the sinh transformation is used, but it can be any transformation.

The main Matlab function behind it is "ActionPostCallback". See http://www.mathworks.fr/fr/help/matlab/ref/zoom.html for more details. You can also use the analog function "ActionPreCallback". These small 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')); 
+3
source

Source: https://habr.com/ru/post/1491645/


All Articles