plotly绘制简单图形<4>--饼形图
程序员文章站
2022-07-14 13:01:45
...
本次说一下饼形图:
目录
1、简单饼形图
import plotly.plotly as py
import plotly.graph_objs as go
labels = ['A','B','C','D']
values = [4500,2500,1053,500]
trace = go.Pie(labels=labels, values=values)
py.iplot([trace], filename='basic_pie_chart')
2、设置修饰
import plotly.plotly as py
import plotly.graph_objs as go
labels = ['A','B','C','D']
values = [4500,2500,1053,500]
colors = ['#FEBFB3', '#E1396C', '#96D38C', '#D0F9B1']#自定义颜色
trace = go.Pie(labels=labels, values=values,
hoverinfo='label+percent', textinfo='value',
textfont=dict(size=20),#数据标签字体大小
marker=dict(colors=colors,
line=dict(color='#000000', width=3)))#设置线框颜色和粗细
py.iplot([trace], filename='styled_pie_chart')
3、甜圈图
import plotly.plotly as py
import plotly.graph_objs as go
fig = {
"data": [
{
"values": [16, 15, 12, 6, 5, 4],
"labels": ['A','B','C','D','E','F'],
"domain": {"x": [0, 1]},#图形区域位置(绘制两个或者多个子图需要用到)
"name": "GHG Emissions",
"hoverinfo":"label+percent+name",
"hole": .4,#内圈大小
"type": "pie"
}],
"layout": {
"title":"图例",
"annotations": [
{
"font": {
"size": 20
},
"showarrow": False,
"text": "GHG",
"x": 0.5,
"y": 0.5#内圈文本位置与上面图形位置对应
}
]
}
}
py.iplot(fig, filename='donut')
PS:右边的图例,可以根据需要进行设置是否显示,点击一下相应变量变成灰色,左边图形会将其剔除
上一篇: 逻辑回归——乳腺癌分类
下一篇: 安卓控件--列表(ListVIew)实现