How do I shift ONLY the y axis in a plot?

조회 수: 6 (최근 30일)
Sam
Sam 2013년 4월 7일
댓글: Walter Roberson 2016년 11월 6일
Hello,
I want to create a graph where y runs from 0 to 500 with intervals of 20 and x runs from -0.3 to 0.3 with intervals of 0.1 each. I have written the following code which plots the graph:
% Plot for lambda = 0.5
n = 30;
dc1 = 1/30*(0.5*66+0.5*62);
dc2 = 1/30*(0.5*57+0.5*55);
dn1 = 1/30*(0.5*40+0.5*30);
dn2 = 1/30*(0.5*35+0.5*20);
dn3 = 1/30*(0.5*20+0.5*27);
e = -0.3:0.01:0.3;
bc1 = 30*dc1*(1+(dc1./(10+e)));
bc2 = 30*dc2*(1+(dc2./(10+e)));
bn1 = 30*dn1*(1+(dn1./(2+e)));
bn2 = 30*dn2*(1+(dn2./(2+e)));
bn3 = 30*dn3*(1+(dn3./(2+e)));
plot(e, bc1, 'g')
hold all
plot(e, bc2, 'r')
hold all
plot(e, bn1, 'b')
hold all
plot(e, bn2, 'y')
hold all
plot(e, bn3, 'black')
When I run this, a normal graph with the y axis at the left appears. What should I add to the code so that I can shift only the y axis at (0,0)such that (1) there's no change in the x axis, (2) no negative y axis appears.
Thank you!
  댓글 수: 4
mohit kumar
mohit kumar 2016년 11월 6일
try this ax.YAxisLocation = 'origin'
Walter Roberson
Walter Roberson 2016년 11월 6일
Note: the answer suggested by mohit kumar is for R2014b or later.

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

답변 (1개)

Walter Roberson
Walter Roberson 2013년 4월 7일
  댓글 수: 1
Sam
Sam 2013년 4월 7일
Hello
I am unable to use the file to shift my axis to the center. When I add PlotAxisAtOrigin(0,0); the y axis disappears completely. I am quite new at Matlab, I will be grateful if you could help me by telling me how to run the file.
Thank you.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by