Plotting images with axis coordinates in Octave
Labels:
octave
It is remarkable that I've struggled to find any examples in the Octave documentation or other people's tutorials or examples on how to plot an image (or matrix) with axis coordinates that aren't the pixel or cell numbers.
function image_with_axes()
clear all;
more off;
% These are our eventual axis coordinates.
x = linspace(-10,10,100);
y = x - 2;
% Generate an Airy disk
[xg,yg]=meshgrid(x,y);
rad = sqrt( xg.^2 + yg.^2);
airy = besselj(1,rad)./rad;
airyintensity = abs(airy).^2;
% The normal imagesc invocation. Note axis ratio.
figure(1);
imagesc(airyintensity)
axis image
%colorbar
% Now invoke with axis vectors before the image/matrix
figure(2);
imagesc(x,y,airyintensity);
axis image
%colorbar
% Demonstrate the coordinates a little more clearly
% Coordinate axes are taken to be the center of the
% image pixel.
a=rand(4);
x=[3:6];
y=[-1:2];
figure(3);
imagesc(x,y,a);
% What about non-linear axes. Not handled correctly like this.
% This case is dealt with another time,
figure(4);
x2=sqrt(x)
y2=x.^2
imagesc(x2,y2,a);
endfunction