I can create a piechart where each wedges is having its size printed like this:
df = pd.DataFrame({'mass': [0.330, 4.87 , 5.97],
'radius': [2439.7, 6051.8, 6378.1]},
index=['Mercury', 'Venus', 'Earth'])
plot = df.plot.pie(y='mass', figsize=(5, 5), autopct= '%.2f')
How can I make it print the values only for a subset (say don't print Mercury)?
lambda
function to conditionally place values with autopct
. As per matplotlib.pyplot.pie
, which is used by pandas.DataFrame.plot.pie
, autopct
can be None
, a str
or a callable function.df = pd.DataFrame({'mass': [0.330, 4.87 , 5.97],
'radius': [2439.7, 6051.8, 6378.1]},
index=['Mercury', 'Venus', 'Earth'])
autopct = lambda v: f'{v:.2f}%' if v > 10 else None
plot = df.plot.pie(y='mass', figsize=(5, 5), autopct=autopct)