Clear Filters
Clear Filters

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

5 views (last 30 days)
Sam
Sam on 7 Apr 2013
Commented: Walter Roberson on 6 Nov 2016
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 Comments
mohit kumar
mohit kumar on 6 Nov 2016
try this ax.YAxisLocation = 'origin'
Walter Roberson
Walter Roberson on 6 Nov 2016
Note: the answer suggested by mohit kumar is for R2014b or later.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 7 Apr 2013
  1 Comment
Sam
Sam on 7 Apr 2013
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!