MATLAB: How to reset axis ticks to normal after I modify them
axisdatetickMATLAB
Suppose I have turned on datetick for a specific axis. Is there a way to turn off / reset the axis ticks to normal mode with 'set' commands?
Best Answer
You want to tell the axes to place the ticks wherever it thinks is best via theXTickMode property. You also want to tell the axes to decide automatically how to label those ticks using theXTickLabelMode property.
You can replace the call togca with the axes handle if you have it. Of course you can set theYTickMode,ZTickMode, ect. properties if you applieddatetick to the y- or z-axis.
This can be done after plotting your figure. The code given below shows an example on how to get the current axis labels and format them into a string with the percent symbol. Once this is done it sets the axis tick labels back to the figure axis.
surf(peaks)
% lines 6,7,8 get the axis labels.
% lines 10,11,12 create the respective Percent vectors
% lines 14,15,16 concatenate the vectors
xticks = [get(gca,'xtick')]'; % Gets the axis tick labels.
yticks = [get(gca,'ytick')]'; % There is a transpose operation here.
zticks = [get(gca,'ztick')]'; %
percentsx = repmat('%', length(xticks),1); % makes a matrix
percentsy = repmat('%', length(yticks),1); % equal to the size
percentsz = repmat('%', length(zticks),1); % of the number of ticks
xticklabel = [num2str(xticks) percentsx];
yticklabel = [num2str(yticks) percentsy]; % concatenates the tick labels
Best Answer