Imagesc and plot on the same graph with two scale

10 ビュー (過去 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 件のコメント
Clément
Clément 2015 年 2 月 13 日
I was doing
figure
imagesc(....)
hold on
plot(...)

サインインしてコメントする。

回答 (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 Center および File ExchangeGraphics Object Properties についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by