Ask Your Question

How to make 1:1 matrix plots?

asked 2010-12-11 06:37:55 -0500

Eviatar Bach gravatar image

updated 2010-12-11 12:45:49 -0500

Evgeny gravatar image


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:

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 flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2010-12-16 09:13:48 -0500

pangard gravatar image

updated 2010-12-16 09:15:48 -0500

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:

edit flag offensive delete link 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: The thing is, the matrix is 201x100, while there are 506x206 pixels. There are enough pixels, so I don't understand why this occurs.

Eviatar Bach gravatar imageEviatar Bach ( 2010-12-16 12:40:09 -0500 )edit

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?)

pangard gravatar imagepangard ( 2010-12-16 21:42:19 -0500 )edit

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.

Eviatar Bach gravatar imageEviatar Bach ( 2010-12-17 09:28:44 -0500 )edit

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.

Jason Grout gravatar imageJason Grout ( 2010-12-21 20:29:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2010-12-11 06:37:55 -0500

Seen: 426 times

Last updated: Dec 16 '10