Question

I am analyzing a dataset in Python for strictly learning purpose. In the code below that I wrote, I am getting some errors which I cannot get rid off. Here is the code first:

plt.plot(decade_mean.index, decade_mean.values, 'o-',color='r',lw=3,label = 'Decade Average')
plt.scatter(movieDF.year, movieDF.rating, color='k', alpha = 0.3, lw=2)
plt.xlabel('Year')
plt.ylabel('Rating')
remove_border()

I am getting the following errors:

1. TypeError: 'str' object is not callable
2. NameError: name 'remove_border' is not defined

Also, the label='Decade Average' is not showing up in the plot.

What confuses me most is the fact that in a separate code snippet for plots (see below), I didn't get the 1st error above, although remove_border was still a problem.

plt.hist(movieDF.rating, bins = 5, color = 'blue', alpha = 0.3)
plt.xlabel('Rating')

Any explanations of all or some of the errors would be greatly appreciated. Thanks

Following the comments, I am posting the data and the traceback below: decade_mean is given below.

year
1970    8.925000
1980    8.650000
1990    8.615789
2000    8.378947
2010    8.233333
Name: rating, dtype: float64

traceback:

TypeError                                 Traceback (most recent call last)
<ipython-input-361-a6efc7e46c45> in <module>()
      1 plt.plot(decade_mean.index, decade_mean.values, 'o-',color='r',lw=3,label = 'Decade Average')
      2 plt.scatter(movieDF.year, movieDF.rating, color='k', alpha = 0.3, lw=2)
----> 3 plt.xlabel('Year')
      4 plt.ylabel('Rating')
      5 remove_border()

TypeError: 'str' object is not callable

I have solved remove_border problem. It was a stupid mistake I made. But I couldn't figure out the problem with the 'str'.

Was it helpful?

Solution

Seems that remove border is not defined. You have to define the function before used.

I do not know where the string error comes, is not clear to me. If you post the full traceback it will be clearer.

Finally your label is not show because you have to call the method plt.legend()

OTHER TIPS

Seems to me that remove_border() is not being recognized as a function. Seeing how you haven't listed a package it belongs to, did you implement this yourself? Python is guessing that remove_border is a string and you're trying to "call it" - treat it like a function. The 2nd error is saying the same thing, the function remove_border isn't defined anywhere that Python can find it.

Licensed under: CC-BY-SA with attribution
Not affiliated with datascience.stackexchange
scroll top