Imagesc and plot on the same graph with two scale
35 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
Antworten (1)
emehmetcik
am 15 Feb. 2015
Bearbeitet: emehmetcik
am 15 Feb. 2015
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 Kommentare
Geoff Hayes
am 15 Feb. 2015
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
am 15 Feb. 2015
Bearbeitet: emehmetcik
am 15 Feb. 2015
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)
Siehe auch
Kategorien
Mehr zu Two y-axis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!