PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, April 23, 2022

[FIXED] How do I change the color of percentage label to be white in pie chart without interfering the text label color?

 April 23, 2022     colors, matplotlib, pie-chart, python     No comments   

Issue

How do I change the color of percentage label to be white in pie chart without interfering the text label color using matplotlib? When I edit textprops={'size': 'x-large','color':'w'}, the text color will turn white which it is not contrast to the background.

labels = df01['new_sentiment']
count = df01['count']

cmap = plt.get_cmap('Greys')
colors = list(cmap(np.linspace(0.45, 0.85, len(count))))

fig1, ax1 = plt.subplots()
ax1.pie(count, labels=labels, autopct='%1.1f%%', textprops={'size': 'x-large'}, colors=colors)

ax1.axis('equal')
plt.title('7D-prior-PM_sem_sen', pad=30)
plt.savefig('04_7D-prior-PM_sem_sen.tiff', dpi=300, format='tiff', bbox_inches='tight')

enter image description here


Solution

You can change the colors of the inner labels like this:

_,_,m = ax1.pie(count, labels=labels, autopct='%1.1f%%', textprops={'size': 'x-large'}, colors=colors)
[m[i].set_color('white') for i in range(len(m))]


Answered By - Benjamin T. Schwertfeger
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing