我想达到的目标:
我想在一个图上创建多个饼图。它们都共享一些类别,但有时具有不同的类别。显然,我希望所有相同的类别都具有相同的颜色。
这就是为什么我创建了一个字典,将类别(= 标签)链接到颜色。有了它,我可以指定饼图的颜色。但我想使用 ggplot 颜色(与 matplotlib.style.style.use('ggplot') 一起提供)。我怎样才能让这些颜色输入我的字典?
# set colors for labels
color_dict = {}
for i in range(0, len(data_categories)):
color_dict[data_categories[i]] = ???
# apply colors
ind_label = 0
for pie_wedge in pie[0]:
leg = ax[ind].get_legend()
pie_wedge.set_facecolor(color_dict[labels_0[ind_label]])
leg.legendHandles[ind_label].set_color_(color_dict[labels_0[ind_label]])
ind_label += 1
Run Code Online (Sandbox Code Playgroud)