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

Python – Plot linear percentage graph

I have this numpy.arr matrix:

[
 [    0     0     0     0     0     0     2     0     2     0     0     1    26     0]
 [    0     0     0     0     0     0     0     0     0     0     0     0     0     4]
 [21477 61607 21999 17913 22470 32390 11987 41977 81676 20668 17997 15278 46281 19884]
 [ 5059 13248  5498  3866  2144  6161  2361  8734 16914  3724  4614  3607 11305  2880]
 [  282  1580   324   595   218   525   150   942   187   232   430   343   524   189]
 [ 1317  6416  1559   882   599  2520   525  2560 19197   729  1391  1727  2044  1198]
]

I’ve just created logaritm heatmap which work as inteded. However I would like to create another heat map that would represent linear scale across rows, and shows each position in matrix corresponding percentage value, while sum of row would give 100%. Without using seaborn or pandas
Something like this:

enter image description here

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

>Solution :

Here you go:

import matplotlib.pyplot as plt
import numpy as np
a = np.array([[0,0,0,0,0,0,2,0,2,0,0,1,26,0],
          [0,0,0,0,0,0,0,0,0,0,0,0,0,4],
          [21477,61607,21999,17913,22470,32390,11987,41977,81676,20668,17997,15278,46281,19884],
          [5059,13248,5498,3866,2144,6161,2361,8734,16914,3724,4614,3607,11305,2880],
          [282,1580,324,595,218,525,150,942,187,232,430,343,524,189],
          [1317,6416,1559,882,599,2520,525,2560,19197,729,1391,1727,2044,1198]])
# normalize
normalized_a = a/np.sum(a,axis=1)[:,None]
# plot
plt.imshow(normalized_a)
plt.show()

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