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

5 vues (au cours des 30 derniers jours)
Leon
Leon le 16 Oct 2019
Modifié(e) : Leon le 16 Oct 2019
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 commentaires
Leon
Leon le 16 Oct 2019
Modifié(e) : Leon le 16 Oct 2019
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 le 16 Oct 2019
Ah, ok...that then does make some sense.

Connectez-vous pour commenter.

Réponse acceptée

dpb
dpb le 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

Plus de réponses (0)

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by