Ask Your Question
1

How to make 1:1 matrix plots?

asked 2010-12-11 13:37:55 +0200

Eviatar Bach gravatar image

updated 2010-12-11 19:45:49 +0200

Evgeny gravatar image

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:

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
1

answered 2010-12-16 16:13:48 +0200

pangard gravatar image

updated 2010-12-16 16:15:48 +0200

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)
edit flag offensive delete link more

Comments

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.

Eviatar Bach gravatar imageEviatar Bach ( 2010-12-16 19:40:09 +0200 )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-17 04:42:19 +0200 )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 16:28:44 +0200 )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-22 03:29:51 +0200 )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

Stats

Asked: 2010-12-11 13:37:55 +0200

Seen: 819 times

Last updated: Dec 16 '10