JackMcKew / pandas_alive

Create stunning, animated visualisations with Pandas & Matplotlib as easy as calling `df.plot_animated()`
MIT License
582 stars 100 forks source link

set colors in pie chart #21

Closed matthme closed 3 years ago

matthme commented 3 years ago

It seems not possible to specify the colors of pie charts. When I pass a list as kwarg (colors=['red', 'blue',...]) I get the following error:

TypeError: pie() got multiple values for keyword argument 'colors'

It seems that there is a color list named "wedge_color_list" passed internally

658 self.ax.pie( --> 659 wedges.values, labels=wedges.index, colors=wedge_color_list, **self.kwargs 660 )

But apparently I cannot overwrite it with my kwarg.

Is this feature not implemented or am I doing something wrong?

JackMcKew commented 3 years ago

Hi @matthme, thank you for raising this!

If you pass your colour list through to pandas_alive as the cmap argument, this should correctly get the colours from your custom list to be used in the thereby later function (inside wedge_color_list)

The problem you're facing is the internals are creating a variable to use for colours, but also by specifying that as a kwarg it'll send 2 keyword arguments to ax.pie hence the error.

matthme commented 3 years ago

Thank you for taking your time, it worked! I was expecting that the same syntax should be used as for the pandas.plot.pie() function...

JackMcKew commented 3 years ago

My line of thinking at the time was to avoid the keyword argument naming clashing and problems arising from that, but open to PRs to unify the keyword argument naming. Although it would mean pandas_alive would need to be verifying all input kwargs then as well