treemap4.py 735 B

1234567891011121314151617
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4. import seaborn as sns
  5. import squarify
  6. data = {'labels': ["video","editing","resource","Subtitle","record","film", "video produce","youtuber","video editing","video resource"],
  7. 'values':[50000,5000,50000,5000,5000,500,5000,50000,50000,5000]}
  8. df = pd.DataFrame(data)
  9. colors=['#fae588','#f79d65','#f9dc5c','#e8ac65','#e76f51','#ef233c','#b7094c'] #color palette
  10. sns.set_style(style="whitegrid") # set seaborn plot style
  11. sizes= df["values"].values# proportions of the categories
  12. label=df["labels"]
  13. squarify.plot(sizes=sizes, label=label, alpha=0.6,color=colors).set(title='Treemap with Squarify')
  14. plt.axis('off')
  15. plt.savefig("../img/filename.png", dpi = 300)