How to create pseudo x-axis (or y-axis) tick labels?
8 views (last 30 days)
Show older comments
I'm writing a program that requires me to change the x or y values by a factor in order to address a bug within Matlab. For example, if my current x-axis values are [0:10:100] and I have to divide the current x values by 33.3 so that the actual x-axis values in the plot will be [0:0.3:3], how do I set the x-axis tick labels, so that my users would still see the original [0:10:100] values as the x tick label?
What is the function to come up with the default x-axis tick values?
Many thanks!
3 Comments
Accepted Answer
dpb
on 16 Oct 2019
With the background as to "why", basic idea would be something like
Ratio=100/3; % the divisor for modifying the actual plotted values
hL=plot(x,y); % plot original data to get default axis pretty labels.
hAx=gca; % get the axes handle
xtk=xticks; % retrieve the tick values
delete(hL); hL=plot(x/Ratio,y); % remove original line; replace with scaled x values
hAx.XTicks=xticks/Ratio; % set ticks at original scaled values
hAx.XTickLabel=xticks; % write the labels to match the original unscaled values
0 Comments
More Answers (0)
See Also
Categories
Find more on Axis Labels 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!