Fundamentals 3 min read

Creating Pie Charts with Python Plotly: A Simple Tutorial

This article demonstrates how to generate a simple pie chart using Python's Plotly library, providing step‑by‑step code, explanation of the class structure, and a visual example for beginners; it also shares the resulting chart image and links to additional technical resources.

FunTester
FunTester
FunTester
Creating Pie Charts with Python Plotly: A Simple Tutorial

The author shares their experience learning Python and the Plotly library, focusing on creating pie charts, which are relatively simple and easy to understand for small datasets.

Below is a complete example that defines a Piecharts class, prints a welcome message, and provides a makePiecharts method to generate an offline Plotly pie chart.

#!/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")

The resulting pie chart is displayed below as an example of the output.

At the end of the article, a curated list of technical and non‑technical articles is provided for further reading, covering topics such as Java one‑line heart shape printing, Linux performance monitoring, API testing, and software testing career advice.

pythonTutorialData VisualizationPlotlypie chart
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.