필터 지우기
필터 지우기

Imagesc and plot on the same graph with two scale

조회 수: 44 (최근 30일)
Clément
Clément 2015년 2월 13일
편집: emehmetcik 2015년 2월 15일
Hello, I am using imagesc to create a picture with data. I am after using plot to plot some data, but the problem is that they don't have the same scale. So i think i need to add a new axis. But the matlab help was not very helpful for imagesc and plot for that.. Can you help me ?
Thanks

답변 (1개)

emehmetcik
emehmetcik 2015년 2월 15일
편집: emehmetcik 2015년 2월 15일
Hi,
You can use imagesc() function with x, y and z inputs. These inputs does not necessarily be the same size as required by 3D plot functions (surf, mesh etc.). For instance;
load clown
imagesc(1:10, [1, 5], X);
hold on;
x = linspace(1, 10, 5);
y = linspace(1, 5, 5);
plot(x, y, 'r', 'linewidth', 2)
plot(x, y(end:-1:1), 'r', 'linewidth', 2)
colormap(map)
axis equal
Note that the loaded image data (X) is 200x320 pixels. However you can control the aspect ratio using proper values for x and y axes limits in the imagesc function. I hope this helps.
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2015년 2월 15일
Clément's answer moved here
In fact, I am showing a picture with imagesc the size of this image is 400x400. I am showing a plot : x :0->400(same size as picture) y :0->1
I just want to put them together on the same graph. But the problem is as there is only one Y scale, data from the plot, are not shown. Because scale is from 0 to 400 and date from plot are from 0 to 1...
I hope you can help me
emehmetcik
emehmetcik 2015년 2월 15일
편집: emehmetcik 2015년 2월 15일
You may try plotyy function of Matlab, together with imagesc.
clear
close all;
load clown
% X = randn(400);
xImage = [0, 400];
yImage = [0, 400];
xData = linspace(0, 400, 5);
yData = linspace(0, 1, 5);
hold on;
h = plotyy(xImage, yImage, xData, yData);
set(h(1), 'ydir', 'reverse')
imagesc(xImage, yImage, X); colormap(map);
You can use surf function as well if the axis directions irritate you :)
clear
close all;
X = randn(400);
xImage = [0, 400];
yImage = [0, 400];
[yLim, xLim] = size(X);
xData = linspace(0, 400, 5);
yData = rand(1, 5);
yData = yData - min(yData);
yData = yData / max(yData);
hold on;
h = plotyy(xImage, yImage, xData, yData);
axis(h(1), [0, 400, 0, 400])
[x, y] = meshgrid(0:399, 0:399);
surf(x, y, ones(size(x)), X); shading flat
view(2)

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by