'XTickLabel' of an axes is of type 'char' and 'XTick' is of type double. Whenever, a semi-log plot is created using SEMILOG function, XTickLabels by default will be shown in exponential form. However, XTicks are stored as doubles and if these Xtick values are assigned back as XTickLabels, the new XTickLabels will not be in exponential format, because of double to char conversion.
The x-axis labels can be changed with the following code:
New_XTickLabel = get(gca,'xtick');
set(gca,'XTickLabel',New_XTickLabel);
These custom XTickLabels do not update dynamically when you zoom into the plot, though the XTicks themselves update. Therefore, the above code has to be executed on each zoom operation. Using the ACTIONPOSTCALLBACK property of the zoom handle, we can execute the above commands after every zoom operation is performed and update the TickLabels to reflect the new axes limits.
Therefore, the code is now :
x= 0:.2:2;
figure
semilogx(10.^x,x)
New_XTickLabel = get(gca,'xtick');
set(gca,'XTickLabel',New_XTickLabel);
zoomH = zoom(gcf);
set(zoomH,'ActionPostCallback',{@zoom_mypostcallback});
The ACTIONPOSTCALLBACK function for the zoom handle is defined as :
function zoom_mypostcallback( ~,~ )
New_XTickLabel = get(gca,'xtick');
set(gca,'XTickLabel',New_XTickLabel);
end
Best Answer