Fixed: 147-4 - Improving Plot Aesthetics - plt.title() error

https://app.dataquest.io/m/147/improving-plot-aesthetics/4/visualizing-the-gender-gap

fig=plt.figure()
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.legend(loc='upper right')
plt.title('Percentage of Biology Degrees Awarded By Gender')
plt.show()

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')
      6 plt.show()

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.

1 Like

Ran for a sixth time with no changes, it now works with no error.

1 Like

Hi @joel.leaman,

This post may be helpful for future cases like this:

I assume that you may have accidentally run something like:
plt.title = 'Percentage of Biology Degrees Awarded By Gender'

Best,
Sahil

1 Like

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.

Thank you,

Joel

1 Like

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?

Thanks!

1 Like

Hi @Aaronask,

To reload a module, you have to do:

Above code assumes that you have imported matplotlib.pyplot as plt

Best,
Sahil