Closed JosephBARBIERDARNAL closed 4 months ago
find a way to automate the mapping between a categorical cmap and a categorical variable (i.e get a list of colors of the same length as the variable:
# load libraries import squarify # pip install squarify (algorithm for treemap) import matplotlib.pyplot as plt from pypalettes import load_cmap import pandas as pd # set a higher resolution plt.rcParams['figure.dpi'] = 300 # create a color palette cmap = load_cmap('Acadia') category_codes, unique_categories = pd.factorize(df['parent']) colors = [cmap(code / (len(unique_categories) - 1)) for code in category_codes] # create a treemap fig, ax = plt.subplots(figsize=(10,10)) ax.set_axis_off() squarify.plot( sizes=df["value"], label=df["name"], ec="white", color=colors, pad=True, ax=ax ) plt.show()
wrong problem. see documentation for a tuto
find a way to automate the mapping between a categorical cmap and a categorical variable (i.e get a list of colors of the same length as the variable: