# Superimposing two figures on the top of each other

조회 수: 67 (최근 30일)
Tommy 2014년 12월 14일
댓글: Tommy 2014년 12월 17일
Hi everyone
I have a question regarding on superimposing two figures.
For example, I have two figures which both have different scaling of x-axis and y-axis. Is there a function that can superimpose these two figures.
For example, I have these two figures.
and
You can see that the x-axes and the y-axes of these two figures are differently scaled. Is it possible that place the first figure on the top the second figure, so that the curly can be seen on the top of the second image. By the way, the second image was created by using imagesc() function.
I tried to use the following code
1. figure(1)
2. imagesc()
3. hold on
4. plot(x,y)
But it did not work due to the difference in x and y axes.
Thank you very much
Tommy

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

### 채택된 답변

Rick Rosson 2014년 12월 14일
m = 1800 / ( 3 - -3) ;
dx = 1800 / 2 ;
u = m*x + dx ;
n = 1000 / ( 1.6 - -1.6 ) ;
dy = 1000 / 2 ;
v = n*y + dy
plot(u,v);
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Tommy 2014년 12월 17일
Thank you very much for your help.

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

### 추가 답변 (2개)

matt dash 2014년 12월 15일
Don't use "hold on" to plot both the image and the plot in the same axes. Instead, create two separate axes on top of each other. Draw the image in the first axes (the one on the bottom) and the plot on top:
figure
axes('position',[something])
imagesc...
axes('position',[same thing],'color','none')
plot(...)
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
matt dash 2014년 12월 16일
The position property sets the position of the axes within the figure. The figure is the window itself. You use the position property in conjunction with the "units" property, which say what units the position is in.
For example:
figure
axes('units','inches','position',[.5 .75 3 2])
makes an axes that is located .5 inches to the left and 0.75 inches up from the bottom-left corner, and is 3 inches wide and 2 inches tall.
If you don't specify the position, it will use a default value. So if you're just using the default anyway now, you don't need to worry about setting a different position. The important thing is just that both axes have the same position, so if you use the default for one, use it for the other too.
Example of using default position:
figure
%make first axes:
a=axes;
image(rgb) %display image
set(a,'xtick',[],'ytick',[]); %remove its ticks
%make 2nd axes:
a2=axes;
x=rand(1,10);
y=rand(1,10);
plot(x,y)
set(a2,'color','none')
Note that both image and plot reset their axes' properties, so i use "set" to change the properties AFTER calling those two functions. Alternatively, you can set the properties before and use "hold on" to prevent the axes from being reset. (Many people think of "hold on" as just being used when you want to plot two things in the same axes, but really what it's doing is stopping plot or image from resetting the axes themselves)
Tommy 2014년 12월 17일

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

Sean de Wolski 2014년 12월 16일
편집: Sean de Wolski 2014년 12월 16일
It's actually there when you plot. Just in the upper left hand corner because that's where the data are located. This will make it more obvious.
imagesc(magic(100))
hold on
plot(1:10,cumsum(rand(1,10)),'r-')
If you want the line in the middle, then adjust the data to be in the middle like Rick has done.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Tommy 2014년 12월 17일
Thank you very much for you advice, I got it working with Rick's method.

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

### 카테고리

Help CenterFile Exchange에서 Formatting and Annotation에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by