How to re-scale an axis
조회 수: 141 (최근 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).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1227702/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1227707/image.jpeg)
댓글 수: 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!