Change Color Of Pie Chart According To Section Label (pandas/matplotlib)
I am working from a DataFrame called plot_df that looks like this: Country Visual Format $ 0 France DEFAULT
Solution 1:
You can use the colors
parameter for pie charts. Since this takes an array, you'll have to create an array that corresponds to your input data for each plot.
cdict = {'DIGITAL': 'r', 'DIGIMAX3D': 'y', 'DIGITAL3D': 'b', ...}
for country in plot_df.index.get_level_values(0).unique():
ax = axes_list.pop(0)
df = plot_df.loc[(country, slice(None))]
colors = [cdict[x] for x in df.index] % colors based on index of input data
df.plot(kind='pie', colors=colors, subplots=True, legend=False, autopct='%1.1f%%', ax=ax)
Post a Comment for "Change Color Of Pie Chart According To Section Label (pandas/matplotlib)"