1

By default, stretch-to-fill is on. So

pixels = ones(100,100)
image(pixels);
colormap([0 0 0; 1 1 1]);

produces

enter image description here

Forcing the axes to be of the same scale, this

pixels = ones(100,100)
image(pixels);
colormap([0 0 0; 1 1 1]);
axis equal;

produces

enter image description here

Obviously, stretch-to-fill is overridden by axis equal. What to do to make them co-exist?

Amro
  • 123,847
  • 25
  • 243
  • 454
Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174

2 Answers2

4

I think you are looking for this call:

figure(1)
image(pixels)
colormap(clr)
axis image        % <-- this call

image

Here is a table of the axes properties manipulated by the various axis modes:

axis_modes_axes_props


You can also do something similar using the imshow function, which acts as a higher-level wrapper to image/imagesc:

figure(2)
imshow(pixels, clr, 'InitialMag','fit', 'Border','loose')
axis on
Amro
  • 123,847
  • 25
  • 243
  • 454
  • Thanks a lot! This pretty much solves my problem. However, why it seems blurred when I try to save it as pdf by `saveas(gcc, file_name, 'pdf');`? [It looks like this.](http://i.stack.imgur.com/9JepL.png) – Sibbs Gambling Jun 05 '14 at 15:42
  • @FarticlePilter: are you on a Mac machine? Other people had this issue with the builtin EPS/PDF viewer: http://stackoverflow.com/a/6617536/97160. If that's the case, try a different viewer – Amro Jun 05 '14 at 15:55
  • Yes, I am on Mac! Thanks a lot again for the great pointer!! So does this mean that I can safely put the seemingly blurry pdf in my paper? Others will see it good? – Sibbs Gambling Jun 05 '14 at 16:06
  • 1
    I cant confirm it myself (I'm on a PC), but I think so. You can try opening the PDF in a modern web browser (Firefox for example has a builtin PDF viewer)... – Amro Jun 05 '14 at 16:12
  • Good advice! It saves me trouble downloading another PDF viewer! – Sibbs Gambling Jun 05 '14 at 16:14
0

The problem is, your axis limits reflect the old size. Maybe there is a generic way to solve it, but setting the limits manually solves it:

xlim([1,100]);ylim([1,100])
Daniel
  • 36,610
  • 3
  • 36
  • 69