Create diagram where y axis has zero limits two times (-1 to 0,0 to 0,0 to 1)
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
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!
More Answers (2)
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.
See Also
Categories
Find more on Axis Labels 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!