#202 Treemap with colors mapped on values

 

 

 

 

 

Here is a tip to map a color on the values of each group of a treemap.

 

 

 

 

 

 


#libraries
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import squarify # pip install squarify (algorithm for treemap)</pre>

# Create a dataset:
my_values=[i**3 for i in range(1,100)]

# create a color palette, mapped to these values
cmap = matplotlib.cm.Blues
mini=min(my_values)
maxi=max(my_values)
norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)
colors = [cmap(norm(value)) for value in my_values]

# Change color
squarify.plot(sizes=my_values, alpha=.8, color=colors )
plt.axis('off')
plt.show()

Leave a Reply

Your email address will not be published.