How to re-scale an axis
390 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I've been searching this community for this answer, but I don't believe what has been suggested to others helps in what I'm trying to accomplish.
The code I have does produce what I am looking to see in terms of a graph, but it sets the axis to the 6th power of 10. The original graph uses seconds. I am trying to rescale the horizontal axis so that it doesn't dictate it as 10 to the 6th. ylim, set gca, and caxis do not actually accomplish what I am trying to do. For reference I attached what my graph looks like and the black/white graph is what I am trying to accomplish. You can see one has a horizontal axis that only goes to 20 seconds (as its supposed to) but mine in the blue goes to 2,000,000. I thought the math worked out if I said this was in milliseconds but I have realized that doesn't make sense so please ignore the label on my graph that says (ms).
0 commentaires
Réponse acceptée
Star Strider
le 11 Déc 2022
Try something like this —
x = linspace(0, 2E6, 2E6);
y = sin(2*pi*x/1E6);
figure
plot(x, y)
figure
plot(x, y)
xt = get(gca, 'XTick');
set(gca,'XTickLabel',xt*1E-5)
The x-tick values are unchanged, however the x-tick labels have been re-scaled.
.
2 commentaires
Plus de réponses (1)
Image Analyst
le 11 Déc 2022
So 2 million milliseconds is 2E-3 * 1E6 is 2E+3 seconds or 2000 seconds. So you can divide your x by 10^6 so that you get numbers in the 0 to 2 range and then just update your label:
plot(x/1E6, y, 'b-');
xlabel('Time (thousands of seconds)');
0 commentaires
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!