Create diagram where y axis has zero limits two times (-1 to 0,0 to 0,0 to 1)

3 views (last 30 days)
Greeting to everyone,
I am trying to write a code that draws a curve like the one in the picture that I attach.My problem is that I cannot find how to set the y axis to take values from -1 to 0,0 to 0,0 to 1. Is it possible to do this in matlab and if so how?
I hope the picture clarifies the problem.Just look at the y values.
Any help would be highly appreciated.Thanks in advance

Accepted Answer

Matt Fig
Matt Fig on 23 Oct 2012
This will get you started. I include most of the properties you will need to make it look right. You should look at the other axes properties. In particular the 'Ydir' property might come in useful.
ax(1) = axes('pos',[.1 .2 .8 .2],...
'ylim',[-1 0])
ax(2) = axes('pos',[.1 .4 .8 .2],...
'xtick',[],'xcolor','w',...
'ylim',[0 1]);
  6 Comments
Matt Fig
Matt Fig on 25 Oct 2012
Nobody will laugh, we all have to start somewhere. I am not sure that I can tell what I am supposed to see on your plot, as opposed to what I do see. All I can tell you is that what you are trying to do is not that trivial. You will simply have to play around with the settings until it looks right. Look at it this way: if you persevere through it you will know MATLAB HG like nobody's business!
Here is another demo to help you along in making sure the lines match up:
figure ('name','test','color',[1 1 1])
x = linspace(-pi,pi,1000);
ax(1)= axes('pos',[.1 .2 .8 .2],...
'ylim',[-pi/2 pi]);
hold all
plot(x,tan(x),'.b')
ax(2) =axes('pos',[.1 .4 .8 .2],'xtick',[],'xcolor','w',...,
'ylim',[-pi pi/2]);
hold all
plot(x,-tan(x),'.r')
set(ax(1),'ytick',[-1:2 pi],...
'ytickl','-1|0|1|2|+/-3.14')
set(ax(2),'ytick',[-2:1],...
'ytickl','-2|-1|0|1|2')
I recommend you explore the xtick, xticklabel, xlim, and other such properties of axes objects, starting with reading this:
docsearch('axes properties')
Good luck!

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 22 Oct 2012
If you were to use plotyy() then you could set() the Position of the second axis to be just below the first, and set() YDir to be reversed on one of the plots.
  1 Comment
Michael Karampasis
Michael Karampasis on 23 Oct 2012
Could you elaborate more on how to to set the Position of the second axis below the first please?
An example would be great.
Thanks again for your answers!

Sign in to comment.


Michael Karampasis
Michael Karampasis on 2 Mar 2013
After much trouble and disappointment I finally managed to do what I wanted. This is a picture to show you the plot of my code.
https://www.dropbox.com/s/6oktbgxqvcqdppn/test.jpg?m
A big thanks to all of you for helping out.
I am acceptins Matt's answer because he was the one who got me going on how to manipulate the axes.
A great thanks to the creator of the oaxes file,John Barber, without which I doubt I could have done my plot as I wanted.
Matlab thriumphs again!!

Community Treasure Hunt

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

Start Hunting!