# import matplotlib.pyplot as plt # import squarify # sizes = [40, 50, 30, 2] # label = ["a", "b", "c", "d"] # color = ["red", "blue", "green", "grey"] # squarify.plot(sizes=sizes, label=label, color=color, alpha=0.6) # plt.axis('off') # plt.show() import matplotlib.pyplot as plt import seaborn as sns import squarify rawdata = sns.load_dataset('titanic') # print(rawdata.head()) n = rawdata.groupby('class')[['survived']].sum() # print(n) a = rawdata.groupby('class')[['survived']].sum().index.get_level_values(0).tolist()#取得index裡的[0]再轉為list # print(a) d = rawdata.groupby('class')[['survived']].sum().reset_index().survived.values.tolist()#This gives us the labels in the form of a list. To get the values corresponding to these labels, use : # print(d) squarify.plot(sizes=d, label=a, alpha=.8) plt.axis('off') plt.show()