How to create pseudo x-axis (or y-axis) tick labels?

8 次查看(过去 30 天)
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 个评论
Leon
Leon 2019-10-16
编辑:Leon 2019-10-16
I use something like the below to allow my cursor to pinpoint a data point. I found that when x and y differs a lot, for example x = [0.0001, 0.0003, 0.0007] and y = [1500, 2300, 2700] and they are densely close to each other, the program will consistently cause errors. The value the program get could be very farther away form the point I'm pinpointing.
Mathworks was able to reproduce the issue and confirmed with me that this was a bug and they are woking to fix it right now.
pt = event.IntersectionPoint;
dist = pdist2(pt,coordinates);

请先登录,再进行评论。

采纳的回答

dpb
dpb 2019-10-16
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 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by