DPM
DPM

Reputation: 935

How to create a matrix colored plot from a list of lists (Python)

My question is: imagine you have a list of length 484 and each element of the list is also a list of length of 484. Basically these lists in the list are going to be the rows in my matrix. I was wandering how can I plot this matrix and the color it based on the values of the matrix.

Thank you in advance.

Upvotes: 1

Views: 348

Answers (2)

Josh123
Josh123

Reputation: 36

You can use:

plt.matshow(my_list)

This would work for your nested list but in general you can convert your nested list into a matrix by calling:

my_array = np.asarray(my_list)

Upvotes: 2

Quang Hoang
Quang Hoang

Reputation: 150735

You can try:

plt.imshow(your_array, cmap='gray')

Upvotes: 1

Related Questions