# How to make 1:1 matrix plots?

Hello,

I want to make a matrix_plot of an array, but it never displays correctly. How would I, for example, make each number in an array into a pixel? I find matrix_plot, in resizing, "corrupts" the image. For example, this is a plot of the Sierpinski triangle: (it also does this on svg plots), and you can see the array isn't translating correctly to pixels. aspect_ratio=1 doesn't work. A sufficiently large figsize works, but I don't see why this is necessary. Isn't there another way?

Thank you.

edit retag close merge delete

Sort by » oldest newest most voted

Your matrix is not square, and the result looks just fine to me. With aspect_ratio=1, all pixels are square, so a 50x100 matrix becomes a 250x500 image. If you want a square picture, you have to compress in the x direction:

matrix_plot(random_matrix(ZZ,50,100)).show(aspect_ratio=2)

more

I'm sorry, that wasn't a good example. However, you can see some rectangular points if you zoom in. Here is an image where this is very clear: http://img687.imageshack.us/img687/3550/matrixt.png. The thing is, the matrix is 201x100, while there are 506x206 pixels. There are enough pixels, so I don't understand why this occurs.

I opened the image with gimp, and cut away the numbers: it's roughly 450x225, and yes, some pixels are square in the vertical direction, other pixels are square in the horizontal direction. I think the rectangular pixels have to do with rescaling without antialias. But: do we want antialias for a matrix_plot? You can also try pylab.imshow, maybe this one uses antialias. (BTW, did you mean 506px × 266px?)

Hmmm, pylab.imshow does it correctly. It's interesting that you say it's probably because of rescaling without anti-aliasing, because when it's saved as an svg it doesn't display correctly either. I would imagine this is because the sage.plot.plot.Graphics object is raster. I'll post this on sage-devel. Thank you for the help.

When you save to svg (or png, for that matter), the saving is passed off to matplotlib. So the decision of raster vs. vector is happening inside of matplotlib, not Sage.