python - Can't add title to pie chart (matplotlib) -
plt.title('survival rate') plt.pie(total_survival, labels=[str(survival_percent) + "% " + "survived", str(100- survival_percent) + "% " + "died"])
i trying add title pie chart getting error:
--------------------------------------------------------------------------- typeerror traceback (most recent call last) <ipython-input-250-7e0f3cd8c625> in <module>() ----> 1 plt.title('survival rate') 2 plt.pie(total_survival, labels=[str(survival_percent) + "% " + "survived", str(100- survival_percent) + "% " + "died"]) 3 typeerror: 'str' object not callable
all resources have seen online write title string within parentheses , don't include argument in plt.pie()
i'm not sure going wrong.
the following code works fine:
import matplotlib.pyplot plt survival_percent = 67 total_survival = [67,33] plt.title('survival rate') plt.pie(total_survival, labels=[str(survival_percent) + "% " + "survived", str(100- survival_percent) + "% " + "died"]) plt.show()
the error therefore produced part of code don't show here. can guess, error 'str' object not callable
suggests, have redefined plt.title
string. happen if example somewhere in code wrote like
plt.title = 'survival rate'
(which of course not reasonable) later on calling (correctly)
plt.title('survival rate')
result in error get.
Comments
Post a Comment