Thanks for your help!
CodePudding user response:
Try using plotly.express
:
import plotly.express as px
users = [80, 40, 1000, 300, 50, 80, 10]
os = ['MacOS', 'Chrome', 'Windows', 'Linux', 'Devian', 'Ubuntu', 'Arch Linux']
fig = px.pie(values=users, names=os,
color_discrete_sequence=px.colors.sequential.RdBu)
fig.update_traces(textposition='outside',
textinfo='percent label value',
marker=dict(line=dict(color='#FFFFFF', width=2)),
textfont_size=12)
fig.show()
The result is quite nice:
CodePudding user response:
Try setting autopct
to what you need:
plt.pie(users,
labels=os,
explode=[0, 0, 0.05, 0, 0, 0, 0],
pctdistance = 1.2,
labeldistance = 1.4,
autopct=lambda x: f'{x:.1f}%\n({(x/100)*sum(users):.0f} users)',
textprops={"family": "Arial", "size": 12},
radius = 2,
colors = ["#9BC2E6", "#FF6600", "#F4B084", "#00B050", "#C6E0B4", "#8633FF", "#CCCCFF"]
)
plt.legend(loc="best", bbox_to_anchor=(2.5,0), title="Operating systems")
Output: