plt.plot(women_degrees['Year'], women_degrees['Biology'], c='blue', label='Women')
plt.plot(women_degrees['Year'], 100-women_degrees['Biology'], c='green', label='Men')
plt.title('Percentage of Biology Degrees Awarded By Gender')
What I expected to happen: Show plot with title
What actually happened:
TypeErrorTraceback (most recent call last)
<ipython-input-1-e508ef7bc51a> in <module>()
3 plt.plot(women_degrees['Year'], 100-women_degrees['Biology'], c='green', label='Men')
4 plt.legend(loc='upper right')
----> 5 plt.title('Percentage of Biology Degrees Awarded By Gender')
TypeError: 'str' object is not callable
Other details: Tried it without line 1, got the same error. Copied-and-pasted the given answer from the ‘Get Help’ dropdown, got the same error.
Ran for a sixth time with no changes, it now works with no error.
This post may be helpful for future cases like this:
In the above post, we discussed that accidentally assigning values to built-in function can generate errors like TypeError: 'float' object is not callable. And the solution was to delete the redefined function using del keyword (for example: del float). What happens here is that it restores the function definition of float function after deleting the value assigned to it. This works well for built-in functions.
However, what if we accidentally redefined a library’s function? For example, what…
I assume that you may have accidentally run something like:
plt.title = 'Percentage of Biology Degrees Awarded By Gender'
Thank you for you reply
@Sahil. Yes, I did initially run that line. I’ve read through the post you’ve linked to, it’ll be useful for when it happens again.
I tried your solution and entered del title. It gave me an error that title was not defined. so I entered del plt.title, which ran without an error. I restarted the page and then added import matplotlib.pyplot as plt to the top of my code. Now it gives me this message:
AttributeError: ‘module’ object has no attribute ‘title’.
How do I reset the matplotlib module?
To reload a module, you have to do:
Above code assumes that you have imported