Ask Your Question
0

MatrixPlots with cell entries

asked 2018-02-22 18:19:50 +0100

jepstra gravatar image

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-02-26 22:38:41 +0100

j.c. gravatar image

updated 2018-02-26 22:43:01 +0100

Something 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).

edit flag offensive delete link more

Comments

@j.c. excellent, really!

jepstra gravatar imagejepstra ( 2018-02-27 11:03:59 +0100 )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

1 follower

Stats

Asked: 2018-02-22 18:19:50 +0100

Seen: 829 times

Last updated: Feb 26 '18