【Plotly-驯化】一文教您画出Plotly中动态可视化饼图:pie技巧

【Plotly-驯化】一文教您画出Plotly中动态可视化饼图:pie技巧
 
本次修炼方法请往下查看
在这里插入图片描述

🌈 欢迎莅临我的个人主页 👈这里是我工作、学习、实践 IT领域、真诚分享 踩坑集合,智慧小天地!
🎇 免费获取相关内容文档关注:微信公众号,发送 pandas 即可获取
🎇 相关内容视频讲解 B站

🎓 博主简介:AI算法驯化师,混迹多个大厂搜索、推荐、广告、数据分析、数据挖掘岗位 个人申请专利40+,熟练掌握机器、深度学习等各类应用算法原理和项目实战经验

🔧 技术专长: 在机器学习、搜索、广告、推荐、CV、NLP、多模态、数据分析等算法相关领域有丰富的项目实战经验。已累计为求职、科研、学习等需求提供近千次有偿|无偿定制化服务,助力多位小伙伴在学习、求职、工作上少走弯路、提高效率,近一年好评率100%

📝 博客风采: 积极分享关于机器学习、深度学习、数据分析、NLP、PyTorch、Python、Linux、工作、项目总结相关的实用内容。

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


下滑查看解决方法

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

  

🎯 1. 基本介绍

  饼图是一种用于展示数据占比的图表,通过将圆分成多个扇形,每个扇形的角度和面积表示数据的比例。Plotly是一个流行的图表库,它能够创建交互式的饼图,允许用户探索数据的分布。

🔍 2. 原理介绍

  饼图的每个扇形由中心角决定,中心角的大小与数据值成比例。如果θ表示中心角,v表示数据值,n表示数据总数,那么:
σ = v n ∗ 360 \sigma=\frac{v}{n}*360 σ=nv360

🔍 3. 画图实践

3.1 数据准备

   我们准备的数据格式如下所示:

# plotly standard imports
import plotly.graph_objs as go
import chart_studio.plotly as py

# Cufflinks wrapper on plotly
import cufflinks

# Data science imports
import pandas as pd
import numpy as np

# Options for pandas
pd.options.display.max_columns = 30

# Display all cell outputs
from IPython.core.interactiveshell import InteractiveShell

InteractiveShell.ast_node_interactivity = "all"

from plotly.offline import iplot
import time
cufflinks.go_offline()

# Set global theme
cufflinks.set_config_file(world_readable=True, theme="pearl")


	claps	days_since_publication	fans	link	num_responses	publication	published_date	read_ratio	read_time	reads	started_date	tags	text	title	title_word_count	type	views	word_count	claps_per_word	editing_days	<tag>Education	<tag>Data Science	<tag>Towards Data Science	<tag>Machine Learning	<tag>Python
119	2	574.858594	2	https://medium.com/p/screw-the-environment-but...	0	None	2017-06-10 14:25:00	41.98	7	68	2017-06-10 14:24:00	[Climate Change, Economics]	Screw the Environment, but Consider Your Walle...	Screw the Environment, but Consider Your Wallet	8	published	162	1859	0.001076	0	0	0	0	0	0
118	18	567.540639	3	https://medium.com/p/the-vanquishing-of-war-pl...	0	None	2017-06-17 22:02:00	32.93	14	54	2017-06-17 22:02:00	[Climate Change, Humanity, Optimism, History]	The Vanquishing of War, Plague and Famine Part...	The Vanquishing of War, Plague and Famine	8	published	164	3891	0.004626	0	0	0	0	0	0
121	50	554.920762	19	https://medium.com/p/capstone-project-mercedes...	0	None	2017-06-30 12:55:00	20.19	42	215	2017-06-30 12:00:00	[Machine Learning, Python, Udacity, Kaggle]	Capstone Project: Mercedes-Benz Greener Manufa...	Capstone Project: Mercedes-Benz Greener Manufa...	7	published	1065	12025	0.004158	0	0	0	0	1	1
122	0	554.078160	0	https://medium.com/p/home-of-the-scared-5af0fe...	0	None	2017-07-01 09:08:00	35.85	9	19	2017-06-30 18:21:00	[Politics, Books, News, Media Criticism]	Home of the Scared A review of A Culture of Fe...	Home of the Scared	4	published	53	2533	0.000000	0	0	0	0	0	0
114	0	550.090507	0	https://medium.com/p/the-triumph-of-peace-f485...	0

3.2 画图实践

   我们根据上述的数据画出不同种类的统计柱状图,具体的代码如下所示:

df.groupby("publication", as_index=False)["word_count"].sum().iplot(
    kind="pie",
    labels="publication",
    values="word_count",
    title="Percentage of Words by Publication",
)

在这里插入图片描述

🔍 4. 注意事项

  • 饼图适用于展示分类数据的比例,但当分类过多时,饼图可能变得难以阅读。
  • 使用go.Pie创建饼图时,labels参数表示分类标签,values参数表示每个分类的数值。
  • Plotly饼图支持多种自定义选项,如颜色、标题、图例等。
  • 交互式饼图允许用户悬停查看每个扇形的具体数值。

🔍 5. 总结

  Plotly的饼图为展示数据占比提供了一种直观且交互性强的方式。通过本博客的代码示例,我们学习了如何使用Plotly绘制饼图,并定制图表的样式和布局。希望这篇博客能够帮助你更好地利用饼图进行数据可视化,使你的数据展示更加生动和有趣。

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

算法驯化师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值