Forum Archive

Another Matplotlib problem

ihf

(I don't know why my previous posting resulted in 2 empty posts which I cannot delete)

Here is another simple example that either crashes Pythonista or gives an error (undoubtedly due to my coding):

```
import matplotlib.pyplot as plt

Pie chart, where the slices will be ordered and plotted counter-clockwise:

labels = ['a', 'b', 'c']
sizes = [.3, .4, .2],
explode = (0, 0, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')

fig1, ax1 = plt.subplots()
ax1.bar(height=sizes, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()```

This crashes 2.7 and gives this traceback for 3.5:

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/4F06F35D-865B-4115-B827-BA053B3731EF/Pythonista3/Documents/matplotlib-piechart-example.py", line 10, in
shadow=True, startangle=90)
TypeError: bar() missing 1 required positional argument: 'left'

cvp

@ihf some different errors:
- a , at end of sizes
- bar instead of pie
- missing explode parameter
- explode length not ok

import matplotlib.pyplot as plt

# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = ['a', 'b', 'c']
sizes = [.3, .4, .2]
explode = [0, 0, 0 ]  # only "explode" the 2nd slice (i.e. 'Hogs')

fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
       shadow=True, startangle=90,explode=explode)
ax1.axis('equal')  # Equal aspect ratio ensures that pie is drawn as a circle.

plt.show()