Visualising a matrix in Python

  • #1

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

Answers and Replies

  • #2
Ibix
Science Advisor
Insights Author
6,472
5,170
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?
 
  • Like
Likes scottdave and jedishrfu
  • #3
308
168
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.
 
  • #5
389
35
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.
 

Related Threads on Visualising a matrix in Python

Replies
0
Views
1K
Replies
6
Views
4K
  • Last Post
Replies
10
Views
1K
  • Last Post
Replies
22
Views
5K
Replies
7
Views
1K
  • Last Post
Replies
2
Views
4K
  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
7
Views
871
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
4
Views
6K
Top