treemap1.py 470 B

12345678910111213141516
  1. # libraries
  2. import matplotlib.pyplot as plt
  3. import squarify # pip install squarify (algorithm for treemap)
  4. import pandas as pd
  5. # Create a data frame with fake data
  6. df = pd.DataFrame({'nb_people':[8,3,4,2], 'group':["group A", "group B", "group C", "group D"] })
  7. # plot it
  8. squarify.plot(sizes=df['nb_people'], label=df['group'], alpha=.8 )
  9. plt.axis('off')
  10. # plt.show()
  11. path = '../img/'
  12. filename = 'filename.png'
  13. saved = path + filename
  14. plt.savefig(saved, dpi = 300)