How to Visualize a Matrix with Non-Numeric Values in Python?

  • Context: Python 
  • Thread starter Thread starter Jozefina Gramatikova
  • Start date Start date
  • Tags Tags
    Matrix Python
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
Jozefina Gramatikova
Messages
62
Reaction score
9
TL;DR
Visualising a matrix in Python
As part of a group project, we have been asked to create a code which produces the following matrix:
1582486152029.png

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

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:
1582486543106.png

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.
 
Physics news on Phys.org
You can type code between
Python:
 and
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?[/color]
 
  • Like
Likes   Reactions: 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 don't 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.