Represent a 2D list as a map of colored squares in Pylab
Question:
Let’s say I have a 2D list that looks like this:
[
['Red','Green','Blue'],
['Red','Red','Green'],
['Red','Red','Red' ]
]
Is there a way I could represent it in Pylab as an map with squares actually being of the color given in a 2D list?
Thank You in Advance.
Answers:
If you can convert your 2D list as a list of numbers, then you can use the imshow function in python
import numpy as np
import matplotlib.pyplot as plt
a = np.array(((1, 2, 3), (4, 5, 6)))
plt.imshow(a)
plt.show()
you will need the numpy and matplotlib packages for this.
Let’s say I have a 2D list that looks like this:
[
['Red','Green','Blue'],
['Red','Red','Green'],
['Red','Red','Red' ]
]
Is there a way I could represent it in Pylab as an map with squares actually being of the color given in a 2D list?
Thank You in Advance.
If you can convert your 2D list as a list of numbers, then you can use the imshow function in python
import numpy as np
import matplotlib.pyplot as plt
a = np.array(((1, 2, 3), (4, 5, 6)))
plt.imshow(a)
plt.show()
you will need the numpy and matplotlib packages for this.