Pregunta

Estoy analizando un conjunto de datos en Python para el aprendizaje estrictamente propósito. En el siguiente código que escribí, estoy consiguiendo algunos errores que no pueden deshacerse fuera. Aquí está el código en primer lugar:

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()

Estoy recibiendo los errores siguientes:

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

Además, la etiqueta = 'Decenio media' está no aparece en la trama.

Lo que me confunde es el hecho de que en un fragmento de código separado para parcelas (véase más adelante), no he tenido la primera de error anterior, aunque remove_border seguía siendo un problema.

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

Cualquier explicaciones de todos o algunos de los errores sería muy apreciada. Gracias

Después de los comentarios, estoy publicando los datos y el rastreo a continuación: decade_mean es la siguiente.

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

rastreo:

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

He resuelto el problema remove_border. Fue un error estúpido que hice. Pero no pude averiguar el problema con el 'str'.

¿Fue útil?

Solución

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()

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
scroll top