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

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

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

I'm thinking that you might need to use innerposition rather than just position ?
I can get the axes with the values I want but I can get them to work with my data.How I can connect my axes with a plot command that does not draw its own axes? I could only connect the axes with my data through a line command but the visual result it is not good.
I can get the axes with the values I want but I can get them to work with my data.How I can connect my axes with a plot command that does not draw its own axes? I could only connect the axes with my data through a line command but the visual result it is not good.
Michael, please remember: When you need help it is always best to paste some working code so that your verbal description of what you see matches what we see... Even if it is only a simplified version of your actual code, make an example that covers the salient points.
Ok don't laugh!I am new at this... It is not complete yet.This is what I have done so far.
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)

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

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.

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!!

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!