Issue
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)?
Solution
- Use a
lambda
function to conditionally place values withautopct
. As permatplotlib.pyplot.pie
, which is used bypandas.DataFrame.plot.pie
,autopct
can beNone
, astr
or a callable function. - See this answer for additional customization options.
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)
Answered By - Trenton McKinney Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.