本人在学习使用 Python 和 plotly 工具的征途中,学习到了饼状图的制作,经过尝试终于得到了一张饼状图。总的来说饼状图比较前两种稍微简单一些,也比较容易理解,数据量并不大,很容易上手。下面分享一些自己的实例和效果图,供大家参考。
代码语言:javascript复制#!/usr/bin/python
# coding=utf-8
import plotly
import plotly.plotly
import plotly.graph_objs as abcc
import plotly.plotly
class Piecharts:
def __init__(self):
print "欢迎使用饼状图生成类"
def makePiecharts(self,labels,values,filename):
trace = abcc.Pie(labels = labels,values= value)
plotly.offline.plot([trace],filename=filename)
if __name__=="__main__":
print 123
labels = ["one","two","three","four","five"]
value = [2123,3123,4355,11023,5225]
drive = Piecharts()
drive.makePiecharts(labels,value,"test.html")
下面是效果图: