Posts

Showing posts with the label Pie Chart

Assign Specific Colours To Data In Matplotlib Pie Chart

Image
Answer : Here's an idea you could try. Make a dictionary from your labels and colors, so each color is mapped to a label. Then, after making the pie chart, go in an assign the facecolor of the wedge using this dictionary. Here's an untested bit of code which might do what you are looking for: import numpy as np import matplotlib.pyplot as plt def mypie(slices,labels,colors): colordict={} for l,c in zip(labels,colors): print l,c colordict[l]=c fig = plt.figure(figsize=[10, 10]) ax = fig.add_subplot(111) pie_wedge_collection = ax.pie(slices, labels=labels, labeldistance=1.05)#, autopct=make_autopct(slices)) for pie_wedge in pie_wedge_collection[0]: pie_wedge.set_edgecolor('white') pie_wedge.set_facecolor(colordict[pie_wedge.get_label()]) titlestring = 'Issues' ax.set_title(titlestring) return fig,ax,pie_wedge_collection slices = [37, 39, 39, 38, 62, 21, 15, 9, 6, 7, 6, 5, 4...