How to re-scale an axis
388 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-12-11
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.
.
更多回答(1 个)
Image Analyst
2022-12-11
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!