I am trying to plot pie chart using varible data.
Below is my code. both Postive_percentage and topic is the list whos
Remove the str(..)
when assigning to labels.
If you want a copy and not just the reference, replace it with list(..)
.
import matplotlib.pyplot as plt
topic = ['VirginAmerica', 'UnitedAirline', 'SouthWestAirline', 'USAirline', 'AmericanAirline', 'SpiritAirline', 'DeltaAirline']
Postive_percentage = [3.917525773195876, 10.0, 6.666666666666667, 10.0, 3.0, 5.0, 5.0]
sizes = Postive_percentage
print(sizes)
labels = list(topic)
# makeitastring = ''.join(map(str, labels))
print(labels)
colors = ['yellowgreen', 'lightgreen', 'darkgreen', 'gold', 'red', 'lightsalmon', 'darkred']
plt.pie(sizes, explode=None, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90) #line 240
#plt.pie(sizes, labels, colors)
plt.axis('equal')
plt.legend()
plt.show()
Explanation:
When using str()
on a list, it makes the whole list as string, including the square-brackets. Therefore, when printing on console, you might have thought that this is a list, while it is just a long string..