MATLAB Answers

matlab plot won't fit figure

51 ビュー (過去 30 日間)
Cameron Fitzgerald
Cameron Fitzgerald 2020 年 4 月 9 日
コメント済み: James Browne 2020 年 4 月 9 日
I'm writing a program that calculates and plots 3 different variable values and plot each set of data side by side for comparison (5 different figures, 3 plots per figure). In all the plots I can use xlim & ylim with the set command to make the plot focus on the area i want and have the axis range i need. But one of the plots it doesn't work.
Graph 1 is what i want the graphs to do
Graph 4 refuses to look like it, changing the axis size just makes the ploted graph bigger or smaller around the data, it doesn't expand the region i want to look at since the values are in a small range. Changing the size with "set" just makes the figure bigger and doesn't affect the graphs.
I just don't understand why its behaving differently from the other graphs. I've uploaded pictures of the plots and code that makes them, as well as a copy of the whole code if that makes it easier to see my mistake.
Thanks for your help, i've looked through a dozen forum posts and none have worked for me

  2 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 4 月 9 日
You explained the reason, yourself. The range of values is small, and you also have axis equal. Is there a specific reason for using axis equal?
Cameron Fitzgerald
Cameron Fitzgerald 2020 年 4 月 9 日
No, it was just one the solutions someone had posted to a similar problem and i had just thrown it in there. Looks like that was the source of my problem, thanks

サインインしてコメントする。

採用された回答

James Browne
James Browne 2020 年 4 月 9 日
編集済み: James Browne 2020 年 4 月 9 日
Hello,
I found your problem. It is the "axis equal" commands in the code for the figure 4 plots (3 instances). I donwloaded your code and ran it without the "axis equal" commands in the figure 4 plot code and got the following result:
If you look at the range of data on the X axis versus the range of data on the Y axis, you can see why. When you use axis equal, it was choosing the scale from the X axis and applying it to the Y axis, which means that the Y axis would be visually compressed.
Another thing that the axis equal command does is sets the axis mode settings to manual. Doing that freezes all axis limits at their current values, which is why your xlim and ylim commands had no effect on your plots. See the help page on "axis" for more info:
I figured out your problem by looking at the follwoing sections from the parameter descriptions, near the bottom of the "axis" help page:
Hope this helps =)

  2 件のコメント

Cameron Fitzgerald
Cameron Fitzgerald 2020 年 4 月 9 日
It helps a lot! Thank you
James Browne
James Browne 2020 年 4 月 9 日
You are very welcome!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by