disturbing axes while zooming in a plot
Show older comments
Hello, I have created a figure (a coordinated map) plotted in Matlab, I want to zoom in a part of the figure by using zoom button in figure window. The problem is while zooming the axes labels will be disturbed and numbers on axis are not correct anymore! As an example the first figure below is original figure and the top y-axis label shows almost 4619023/ The second attached picture is a zoomed-in one (on the top on y-axis area on the first picture) but it shows almost 4619009 on y-axis! Does anyone please have a solution for this problem? Thanks in advance.
The piece of plotting code that I use if it's needed:
plot(cell2mat(D{:,6}),cell2mat(D{:,4}),'*')
text(cell2mat(D{:,6}),cell2mat(D{:,4}),cellstr(num2str([1:height(D)]')))
daspect([1 1 1]);
%%to make numbers on labels not logarithmic
set(gca,'YTickLabel',num2str(get(gca,'YTick').'))
set(gca,'XTickLabel',num2str(get(gca,'XTick').'))
3 Comments
You are manually setting the tick labels. When you zoom these will no longer get auto updated so you will likely end up with a mess as these tick labels get applied to totally different ticks after the zooming.
Manually setting tick labels does not go well with zooming. You'd have to add your own post-zoom callback to recalculate the tick labels for the new ticks I would think.
Take a look at
doc zoom
In particular the section on Zoom mode callbacks and the use of the zoom mode object. You can do some useful things with this object, including two that are of interest:
ActionPreCallback
ActionPostCallback
Setting these allows you to define behaviour that happens before and after the actual zooming.
You may want to set the XTickLabelMode to auto in the pre callback and then insert the code you have above that over-rides labels into the ActionPostCallback in order to have them corrected each time you zoom.
Sanaz Esmaeili
on 5 Jun 2017
Adam
on 6 Jun 2017
Excellent. I'll add it as an answer, just for future reference for anyone.
Answers (1)
Adam
on 6 Jun 2017
You are manually setting the tick labels. When you zoom these will no longer get auto updated so you will likely end up with a mess as these tick labels get applied to totally different ticks after the zooming.
Manually setting tick labels does not go well with zooming. You'd have to add your own post-zoom callback to recalculate the tick labels for the new ticks I would think.
Take a look at
doc zoom
In particular the section on Zoom mode callbacks and the use of the zoom mode object. You can do some useful things with this object, including two that are of interest:
ActionPreCallback
ActionPostCallback
Setting these allows you to define behaviour that happens before and after the actual zooming.
You may want to set the XTickLabelMode to auto in the pre callback and then insert the code you have above that over-rides labels into the ActionPostCallback in order to have them corrected each time you zoom.
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!