Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Heatmap type plot with binary vectors

I have data in the form of vectors like this:

[
[a, 0, 1, 1, 0],
[b, 1, 0, 0, 1],
[c, 1, 0, 1, 0],
...
]

I want to plot the data so that it looks kind of like this:
enter image description here

Where 0th element in each array is on the y axis and elements 1:4 of the array are plotted along the x axis. Specifically, each element 1:4 is plotted along a column and is yellow for 0 and purple for 1.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

What is such a plot called and how do I make one?

>Solution :

I think it’s called imshow/matshow:

# `lst` is your list
plt.imshow(np.array([a[1:] for a in lst]).T)       
plt.xticks(range(len(lst)),labels=[a[0] for a in lst])

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading