Python ProgrammingPython Programming

How to set the direction of pie chart in Python Matplotlib?

Clockwise vs anti-clockwise pie charts:

To specify fractions direction of the pie chart, you must set the counterclock parameter to True or False (value is True by default).

import matplotlib.pyplot as plt

labels = ['India', 'Canada', 'Japan', 'Australia', 'Russia']
sizes = [31, 19, 15, 14, 21]  # Add upto 100%

# Plot the pie chart
plt.pie(sizes, labels=labels, counterclock=False, startangle=90)

# Equal aspect ratio ensures that pie is drawn as a circle.

# Display the graph onto the screen

Set direction of pie charts
plt.pie(sizes, labels=labels, counterclock=True, startangle=90)

Set direction of pie charts