#202 Treemap with colors mapped on values






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







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
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 )
  • Sponsors


    • I am using anaconda version of python. I try pip install squarify and I can not import squarify. What is most efficient way to use squarify with Anaconda Jupyter notebook?

      • Hi Will,

        I followed the instruction of the GitHub page of the scarify library. I used pip as well and it worked fine. May be you could try to install it from source doing

        git clone git://github.com/laserson/squarify.git
        cd squarify
        python setup.py install


    Leave a Reply

    Your email address will not be published.