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
Click For Summary

Discussion Overview

The discussion revolves around visualizing a matrix containing non-numeric values (specifically the characters x, w, m, o) in Python, particularly using the Matplotlib library. Participants explore various approaches to represent this matrix graphically, considering the challenges posed by the non-numeric nature of the data.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks assistance in visualizing a matrix with non-numeric values and mentions attempts using imshow and Matplotlib without success.
  • Another participant suggests replacing the letters in the matrix with numbers to utilize existing code for numeric matrices.
  • A different participant points out that the initial image shared does not represent a single matrix but rather an array of matrices or a tensor, implying a need for 3D visualization.
  • One participant references a Matplotlib chart for image display, suggesting it could be applicable for visualizing the data.
  • Another participant notes the lack of a clear method to convert the specific characters to colors and proposes creating a numeric matrix where each symbol corresponds to a different number for visualization purposes.

Areas of Agreement / Disagreement

Participants express differing views on how to approach the visualization of the matrix, with no consensus on a single method or solution. There are competing suggestions regarding the representation of non-numeric values and the need for potential 3D visualization.

Contextual Notes

Participants have not fully resolved the assumptions regarding the conversion of non-numeric values to numeric equivalents or the implications of visualizing a tensor versus a standard matrix.

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

Similar threads

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