On Nov 10, 2009, at 11:25 PM, Jonathan Bober wrote:

> Does anyone know how to plot a matrix so that each pixel in the output
> picture corresponds precisely to an entry in the matrix?
>
> To see the problem that I have, you might see the odd results that  
> occur
> when you do:
>
> M = zero_matrix(GF(2), 1000)
> sage: M
> 1000 x 1000 dense matrix over Finite Field of size 2
> sage: for n in range(1000):
> ....:     for m in range(1000):
> ....:         if (n + m) % 2 == 0:
> ....:             M[n,m] = 1
> ....:
> sage: M
> sage: plot(M).show(figsize=[5,5])
> sage: plot(M).show(figsize=[6,6]) # <-- This one in particular might  
> be very surprising.
> sage: plot(M).show(figsize=[7,7])
>
> I'm pretty sure that I understand why these problems occur, and I'm  
> not
> sure if there is any good way to fix them.
>
> What I would like to be able to do is be able to take the above matrix
> and produce an image with alternating black and white pixels, for
> example. Is this possible? I'm not particularly concerned about the
> border, or labels for the matrix, right now. I just want the picture  
> of
> the matrix itself to look right.

For matrices over F_2 you can do

sage: from sage.matrix.matrix_mod2_dense import to_png
sage: to_png(M, "M.png")

Otherwise, I'm not sure how to do this, as it uses the numpy  
_render_on_subplot method which does its own interpolation. (This is  
also an issue with contour and complex plots, where the lack of pixel  
<-> point relationship makes for fuzzier plots.)

- Robert

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to