# Visualising a matrix in Python

## Summary:

Visualising a matrix in Python

## Main Question or Discussion Point

As part of a group project, we have been asked to create a code which produces the following matrix:

I want to create the graphics of this in a way that looks similar to this:

But of course with different number of cells, different colours, etc. The problem is that from what I have found online is that this works if you have only numbers in your matrix, but here we have x,w,m,o. This is the main bit of the program:

I have tried to use imshow and matplotlib to create the graphics, but it didn't work. Please tell me what I need to type. Thank you.

Related Programming and Computer Science News on Phys.org
Ibix
You can type code between [code=python] and [/code] tags:
Python:
import sys
for i in range(10):
print(i)
That's better than pasting images - we can quote from it and refer to line numbers.

You say you've found code that would do what you want if your matrix had numbers. So why not put numbers into it in place of the letters?

scottdave and jedishrfu
I agree with @Ibix. It would also help if you tell us more about the problem to solve. In your first picture I dont see a single matrix, but rather array of metrices, or tensor. In such case, you would rather need a 3D visualization.

There is no obvious rule how to convert 'x', '0', 'm', ... to colors. You could create a matrix of numbers where each of the symbols is replaced by a different number. Then, you can use the code you already used to show a matrix visually on this new matrix.