ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 21 Dec 2010 20:29:51 -0600How to make 1:1 matrix plots?http://ask.sagemath.org/question/7806/how-to-make-11-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:
![Sierpinski triangle](http://img109.imageshack.us/img109/7189/sage0.png)
(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.Sat, 11 Dec 2010 06:37:55 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/Answer by pangard for <p>Hello,</p>
<p>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:</p>
<p><img alt="Sierpinski triangle" src="http://img109.imageshack.us/img109/7189/sage0.png"/></p>
<p>(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?</p>
<p>Thank you.</p>
http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?answer=11872#post-id-11872Your 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)Thu, 16 Dec 2010 09:13:48 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?answer=11872#post-id-11872Comment by pangard for <p>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:</p>
<pre><code>matrix_plot(random_matrix(ZZ,50,100)).show(aspect_ratio=2)
</code></pre>
http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22389#post-id-22389I 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?)Thu, 16 Dec 2010 21:42:19 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22389#post-id-22389Comment by Eviatar Bach for <p>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:</p>
<pre><code>matrix_plot(random_matrix(ZZ,50,100)).show(aspect_ratio=2)
</code></pre>
http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22387#post-id-22387Hmmm, 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.Fri, 17 Dec 2010 09:28:44 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22387#post-id-22387Comment by Eviatar Bach for <p>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:</p>
<pre><code>matrix_plot(random_matrix(ZZ,50,100)).show(aspect_ratio=2)
</code></pre>
http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22393#post-id-22393I'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.Thu, 16 Dec 2010 12:40:09 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22393#post-id-22393Comment by Jason Grout for <p>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:</p>
<pre><code>matrix_plot(random_matrix(ZZ,50,100)).show(aspect_ratio=2)
</code></pre>
http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22370#post-id-22370When 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.Tue, 21 Dec 2010 20:29:51 -0600http://ask.sagemath.org/question/7806/how-to-make-11-matrix-plots/?comment=22370#post-id-22370