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

조회 수: 5 (최근 30일)
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

채택된 답변

Matt Fig
Matt Fig 2012년 10월 23일
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
Michael Karampasis
Michael Karampasis 2012년 10월 24일
편집: Michael Karampasis 2012년 10월 24일
Ok don't laugh!I am new at this... It is not complete yet.This is what I have done so far.
Matt Fig
Matt Fig 2012년 10월 25일
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!

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 22일
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
Michael Karampasis
Michael Karampasis 2012년 10월 23일
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!

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


Michael Karampasis
Michael Karampasis 2013년 3월 2일
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!!

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by