How to change the scale of plot axes? How to plot circle using separate x and y equations?

5 ビュー (過去 30 日間)
Hi, I need to have this kind of result: (the scaling of the axes, and the graph of the 3rd and 6th subplots)
Here is my code:
for k = 1:6
ax(k) = subplot(3,3,k);
end
subplot(ax(1))
fplot(@(x) cos(x))
xlabel('x')
ylabel('y')
title('cos(x)')
axis([-5 5 -1 1])
subplot(ax(2))
fplot(@(x) cos(x))
xlabel('x')
ylabel('y')
title('cos(x)')
axis([0 2 -1 1])
subplot(ax(3))
fimplicit(@(x,y) (1/y)-(log(y))+(log(-1+y))+x-1)
xlabel('x')
ylabel('y')
title('1/y-log(y)+log(-1+y)+x-1=0')
axis([-5 5 -5 5])
subplot(ax(4))
fimplicit(@(x,y) x^2+y^2-4)
xlabel('x')
ylabel('y')
title('x^2+y^2-4=0')
axis([-5 5 -5 5])
%Plot for x^3+y^3-5xy+1/5=0
subplot(ax(5))
fimplicit(@(x,y) x^3+y^3-(5*x*y)+(1/5))
xlabel('x')
ylabel('y')
title('x^3+y^3-5xy+1/5=0')
axis([-2 2 -3 3])
t = -5:5;
x = sin(t);
y = cos(t);
subplot(ax(6))
plot(x,y)
xlabel('x')
ylabel('y')
title('x = sin(t),y = cos(t)')
axis([-0.5 0.5 -1 1])
This is the result I get using my code:
Thank you in advance!

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 7 月 23 日
Try adding 'axis equal'. You can see additional options here.
You already have the equations for getting X and Y of a circle. The problem is your resolution. Too few points, and your circle might look like an octogon, or a square. The circle will look smoother the smaller the step between each point is. Adjust this by modifying t. For example
t = -5:0.5:5
See here for more. Change the value in the middle until you get the output you like.
  5 件のコメント
Cris LaPierre
Cris LaPierre 2020 年 7 月 24 日
Axis equal makes the scale the same in x and y. This is not applicable for every single subplot. For example, the top left has a range in Y of 2, but a range of 10 in X.
Also note that this is a 2x3 suplot grid, not 3x3.
Fix the warnings you get in the code by using elementwise operators in your equations.
Note that, at least for the trig functions, it's most likely the limits are some multiple of pi.
This is clearly an exercise to get you to explore various axis properties - limits, modes, etc. You do not do the same thing in every plot.
Cris LaPierre
Cris LaPierre 2020 年 7 月 24 日
Oh, great! Glad it worked.

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

その他の回答 (1 件)

Arthur Roué
Arthur Roué 2020 年 7 月 23 日
A call to
axis equal
After creating your plot will set the same length for the data units along each axis.
  2 件のコメント
Roxanne Esguerra
Roxanne Esguerra 2020 年 7 月 24 日
I tried adding that to each subplot and it still didn't result to the required scaling of the axes.
Is it possible to have increments in the axis limits?
Roxanne Esguerra
Roxanne Esguerra 2020 年 7 月 24 日
Thanks for the help :)

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by