Simple Pie Chart
Simple Pie Chart
This is a really simple example of a pie chart in MatPlotLib.
from matplotlib import pyplot as plt
import numpy as np
N = 100
data = list(np.random.exponential(size=N))
pie_data = []
for bound in range(1,6):
pie_data.append(len([point for point in data if bound-1 < point < bound]))
For the plt.pie()
function, you pass the data to the function in the form of relative sizes. For most users this means that you'll be using the len()
function over some range of your data.
You pass the labels for the data in as the keyword argument labels
.
plt.pie(pie_data, labels=[str(x) for x in range(1,6)])