Simple question here, I am creating a pie chart in pandas for the value counts of a dataset's regional spread:
df['region'].value_counts().plot.pie
I want to use the colormap "cool" to color this so it matches my other visualizations, is this possible or am I oversimplifying? Do I need to assign a color to each region or can I somehow just add a colormap='cool' somewhere in here? New to visualizations here...
When not plotting straight from pandas, pie uses the colors argument, which takes a list of color codes.
You can retrieve color codes from some matplotlib colormaps using plt.cm.desired_colormap_name.colors
For example:
import matplotlib.pyplot as plt
import pandas as pd
s = pd.Series([1,2,3,4,5])
plt.pie(s, colors=plt.cm.Pastel2.colors)
plt.show()

Colormap names here: https://matplotlib.org/stable/tutorials/colors/colormaps.html
You can pass the argument cmap='cool' to the .pie method. Here's an example:
import matplotlib.pyplot as plt
import pandas as pd
s = pd.Series([1,2,3,4,5])
s.plot.pie(cmap='cool')
plt.show()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With