Skip to content

Instantly share code, notes, and snippets.

@lukauskas
Created August 28, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukauskas/566fef80c9ff15d47ca5793feb335a73 to your computer and use it in GitHub Desktop.
Save lukauskas/566fef80c9ff15d47ca5793feb335a73 to your computer and use it in GitHub Desktop.
Multiple Pie Charts
%config InlineBackend.figure_format = 'retina'
%matplotlib inline

from matplotlib import pyplot as plt
PIE_SLICES = [
    [10, 20, 30, 40], # Pie 1 (arbitrary units, matplotlib will transform them to pct total.)
    [1, 1, 2, 2], # Pie 2
    [0.1, 0.8, 0.1], # Pie 3
]
plt.figure(figsize=(5,5))
ax = plt.gca()

PIE_RADIUS = 0.2

for i, slices_ in enumerate(PIE_SLICES, start=1):
    pie_x = i * PIE_RADIUS * 2.5
    pie_y = 1.0
    
    ax.pie(slices_, center=(pie_x, pie_y), radius=PIE_RADIUS)
    ax.text(pie_x, pie_y + PIE_RADIUS * 1.1, f"Pie {i}", ha='center', va='bottom')
    pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment