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

  • Thread starter Thread starter Jozefina Gramatikova
  • Start date Start date
  • Tags Tags
    Matrix Python
Click For Summary
The discussion revolves around creating a visual representation of a matrix containing non-numeric elements (x, w, m, o) using Python's Matplotlib. The original poster seeks guidance on how to adapt existing code that works with numeric matrices to accommodate their specific matrix. Suggestions include replacing the letters with corresponding numbers to facilitate visualization, as Matplotlib's imshow function typically requires numeric input. Additionally, the conversation touches on the possibility of needing a 3D visualization if the matrix represents an array of matrices or tensors. The use of color mapping to represent different symbols in the matrix is also highlighted, emphasizing the need to establish a conversion method from symbols to colors for effective graphical representation.
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.
 
Technology 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 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K