How to draw a nicer graph

조회 수: 1 (최근 30일)
Yuechuan Chen
Yuechuan Chen 2019년 10월 15일
댓글: Yuechuan Chen 2019년 10월 15일
x=-2*pi:pi/100:2*pi;
y=sin(3*x);
z=cos(3*x);
plot(x,y,'k',x,z,'b')
plot(x,y,'--',x,z,'-')
Hi,
I've plotted the graph of cos(3x)=sin(3x) (left), but it looks rather messey, there's excess space on the left of the graph and also it's a bit too tall. Is there a way to make to so that it has some resemblance of the graph of the right? i.e. touching the y axis and more round-looking.
Thank You!!
sin3xcos3x.png nicer.png
  댓글 수: 2
darova
darova 2019년 10월 15일
manipulate with axis command
Yuechuan Chen
Yuechuan Chen 2019년 10월 15일
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2019년 10월 15일
Use the xlim function to change the limits of your X axis.
Also FYI you don't need to call plot twice. You can specify both a color and a line style (and a marker too, if you wanted) in one call. This can be particularly useful if you are plotting a lot of data, as it reduces the number of lines you create which means you need fewer copies of the data stored in those lines' properties.
% Make data
x=-2*pi:pi/100:2*pi;
y=sin(3*x);
z=cos(3*x);
% Plot with color and line style in the linespec for each line
plot(x,y,'k--',x,z,'b-')
% Change axes limits
xlim([-2*pi, 2*pi])
  댓글 수: 1
Yuechuan Chen
Yuechuan Chen 2019년 10월 15일
Perfect, thank you so much for the help! Learning something new everyday :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by