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, 27 Feb 2018 04:03:59 -0600MatrixPlots with cell entrieshttp://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/ Is there a nice way to combine `MatrixPlot` with something else to have a label in each cell such as in this picture?
![image description](https://i.stack.imgur.com/bgNdN.png)Thu, 22 Feb 2018 11:19:50 -0600http://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/Answer by j.c. for <p>Is there a nice way to combine <code>MatrixPlot</code> with something else to have a label in each cell such as in this picture?</p>
<p><img alt="image description" src="https://i.stack.imgur.com/bgNdN.png"></p>
http://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/?answer=41272#post-id-41272Something like this works:
# make some random matrix
A = random_matrix(ZZ,7,7)
# make a graphics object consisting of the values of A
g = sum([text(str(A[j,k]),(j,k)) for j in range(7) for k in range(7)])
# matrix plot A and then combine with the text
g2=matrix_plot(A,cmap='rainbow',colorbar=True)
h = g2+g
# for some reason the graphics window resizes to the shape of the added text graphics
# regardless of whether h = g + g2 or h = g2 + g
h.SHOW_OPTIONS['xmax'] = 6.5
h.SHOW_OPTIONS['xmin'] = -.5
h.SHOW_OPTIONS['ymax'] = 6.5
h.SHOW_OPTIONS['ymin'] = -.5
# show result
h.show()
Image here: https://imgur.com/a/czhRS (I don't have enough points to embed it).Mon, 26 Feb 2018 15:38:41 -0600http://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/?answer=41272#post-id-41272Comment by jepstra for <p>Something like this works:</p>
<pre><code># make some random matrix
A = random_matrix(ZZ,7,7)
# make a graphics object consisting of the values of A
g = sum([text(str(A[j,k]),(j,k)) for j in range(7) for k in range(7)])
# matrix plot A and then combine with the text
g2=matrix_plot(A,cmap='rainbow',colorbar=True)
h = g2+g
# for some reason the graphics window resizes to the shape of the added text graphics
# regardless of whether h = g + g2 or h = g2 + g
h.SHOW_OPTIONS['xmax'] = 6.5
h.SHOW_OPTIONS['xmin'] = -.5
h.SHOW_OPTIONS['ymax'] = 6.5
h.SHOW_OPTIONS['ymin'] = -.5
# show result
h.show()
</code></pre>
<p>Image here: <a href="https://imgur.com/a/czhRS">https://imgur.com/a/czhRS</a> (I don't have enough points to embed it).</p>
http://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/?comment=41279#post-id-41279@j.c. excellent, really!Tue, 27 Feb 2018 04:03:59 -0600http://ask.sagemath.org/question/41234/matrixplots-with-cell-entries/?comment=41279#post-id-41279