
Plotting an image, how to show origin tick marks?
21 次查看(过去 30 天)
显示 更早的评论
I'm trying to show the origin in this plot, but it is not working, any suggestions?
x1 = linspace(-1,1,256);
x2 = x1.';
A = 1;
f1 = (4);
f2 = (3);
ph = pi;
u = A*cos(2*pi*(f1*x1+x2*f2)/2+ph);
figure(1)
imshow(u)
title('Cosine Function, f=(4,3)c/ph')
xlabel('x1[ph]')
ylabel('x2[ph]')
axis on
xticks([0 50 100 150 200 250])
xticklabels({'0','50','100','150','200','250'})
yticks([0 50 100 150 200 250])
yticklabels({'0','50','100','150','200','250'})
In addition to this, I need to make another plot of this 3-d cosine, is there a command I can use with imshow to alter this image to give a perspective shot? Maybe via axis?
0 个评论
回答(3 个)
Image Analyst
2017-1-27
You can use imshow and pass in XData and YData. You can use line() to draw across the image at the origin/main axes if you want:
fontSize = 20;
x1 = linspace(-1,1,256);
x2 = x1.';
A = 1;
f1 = 4;
f2 = 3;
ph = pi;
u = A*cos(2*pi*(f1*x1+x2*f2)/2+ph);
imshow(u, 'XData', x1, 'YData', x2);
title('Cosine Function, f=(4,3)c/ph', 'FontSize', fontSize)
xlabel('x1[ph]', 'FontSize', fontSize)
ylabel('x2[ph]', 'FontSize', fontSize)
% Put tick marks at specified locations:
axis on
xticks([-1:0.2:1])
yticks([-1:0.2:1])
% Put lines across the entire image, in the overlay, where the main axes should be.
line(xlim, [0,0], 'LineWidth', 2, 'Color', 'r');
line([0,0], ylim, 'LineWidth', 2, 'Color', 'r');

0 个评论
Adam
2017-1-27
编辑:Adam
2017-1-27
[0, 0] is not visible on an image axes normally. The origin is at [0.5 0.5] because the first pixel is centred at [1 1], extending out in all directions by 0.5 to meet up with the next pixel.
You could force [0 0] to be on the axes by e.g.
xlim( hAxes, [0 250] )
ylim( hAxes, [0 250] )
but you may well get a small white border round your image in that case as there is no data between 0 and 0.5.
Alternatively you can use the XTickLabel property of axes instead and map and XTick at 0.5 onto a label of 0 and the same with YTickLabel.
It can all get a bit messy though, especially if you allow zooming and panning.
0 个评论
Jan
2017-1-27
imshow draws the image from the coordinates 1 to 256. Then the data do not contain the 0 and therefore no ticks appear at the origin.
If you use image instead, you can specify the X and Y coordinates.
What do you want to see in the tilted view? A tilted grey image or do you want a 3D graph with the Z position defined by the value of u?
4 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!