👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • 1. Basic Pie Chart
  • 2. Fancy Pie Chart
  • 3. Donut Chart

Was this helpful?

  1. 3. Matplotlib

3.8 Pie Chart

Previous3.7 Lollipop ChartNext3.9 Venn Chart

Last updated 4 years ago

Was this helpful?

A Pie Chart can only display one series of data. Pie charts show the size of items (called wedge) in one data series, proportional to the sum of the items.

Parameters

Description

x

array-like. The wedge sizes.

labels

A list. A sequence of strings providing the labels for each wedge.

colors

A sequence of matplotlib color args through which the pie chart will cycle.

autopac

A string used to label the wedges with their numeric value.

The label will be placed inside the wedge.

1. Basic Pie Chart

plt.figure(1,figsize = (6,6))

labels = ['Apple', 'Banana', 'Orange', 'Kiwi']
sizes = [38.4, 40.6, 20.7, 10.3]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
patches, texts = plt.pie(sizes, colors=colors, shadow=True, startangle=90)
plt.legend(patches, labels, loc="best")
plt.axis('equal')
plt.tight_layout()
plt.show()

Now we have a basic pie chart. Of course, it can be and should be presented better.

For example, the legend position is weird and overlapped with the pie. Also, we can not see any numbers from it and we don't know which part we should focus on. Therefore, Let's do some changes.

2. Fancy Pie Chart

plt.figure(1,figsize = (6,6))
labels = ['Apple', 'Banana', 'Orange', 'Kiwi']
sizes = [38.4, 40.6, 20.7, 10.3]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
explode = (0, 0.1, 0, 0)  #explode 1st slice

plt.pie(sizes, explode=explode, labels=labels, colors=colors,
autopct='%1.1f%%', shadow=True, startangle=-45)  # add shadow, show percentage
plt.axis('equal')
plt.title('Fancy Pie Chart')

3. Donut Chart

plt.figure(1,figsize = (6,6))
labels = ['Apple', 'Banana', 'Orange', 'Kiwi']
sizes = [38.4, 40.6, 20.7, 10.3]
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']

plt.pie(sizes, labels=labels, colors=colors,
autopct='%1.1f%%', startangle=-45, shadow=True) 

#draw circle
centre_circle = plt.Circle((0,0),0.75,fc='white') #0.75 is the circle size
fig = plt.gcf()
fig.gca().add_artist(centre_circle)

plt.axis('equal')
plt.title('Donut Chart')
  • Simple is better than complex.

  • Readability counts. Do not make it hard to read.

As we discussed in Pie charts are poor at communicating data, especially for complicated data. Although it looks awesome, it delivers less information than tables or column charts.

Features of Pie Chart,
Basic Pie Chart
Fancy Pie Chart
Donut Chart