"subplot" is giving error in "title"

Asked

Viewed 32 times

0

I’m trying to spin a subplot,only that the title(title):

> TypeError Traceback (most recent call last)
> ~\AppData\Local\Temp/ipykernel_17364/305905731.py in <module> 4
> graf_dados=df.groupby('lojas_cidade').count().produto_valor.sort_values(ascending=False)
> 5 plt.bar(graf_dados.index,graf_dados.values) ----> 6
> plt.title('Vendas por Loja') 7 plt.xticks(rotation=90) 8 TypeError:
> 'str' object is not callable

What can it be?

When I take the title works normally.

plt.figure(figsize = (10,7))

plt.subplot(2,2,1)
graf_dados=df.groupby('lojas_cidade').count().produto_valor.sort_values(ascending=False)
plt.bar(graf_dados.index,graf_dados.values)
plt.title('Vendas por Loja')
plt.xticks(rotation=90)

plt.subplot(2,2,2)
graf_dados=df.groupby('produto_produto').count().produto_valor.sort_values(ascending=False)
plt.bar(graf_dados.index,graf_dados.values)
plt.title('Produtos que mais Vendem')
plt.xticks(rotation=90)

plt.subplot(2,2,3)
graf_dados = df[['lojas_cidade','produto_valor']].groupby('lojas_cidade').sum().produto_valor.sort_values(ascending=False)
plt.bar(graf_dados.index,graf_dados.values)
plt.title('Receita por Loja')
plt.xticks(rotation=90)

plt.subplot(2,2,4)
graf_dados=df[['produto_produto','produto_valor']].groupby('produto_produto').sum().produto_valor.sort_values(ascending=False)
plt.bar(graf_dados.index,graf_dados.values)
plt.xticks(rotation=90)
plt.title=('Receitas por Produto')
plt.tight_layout()
  • What kind of error? Talk more about and if possible include the error message in the question....

  • Typeerror Traceback (Most recent call last) ~ Appdata Local Temp/ipykernel_17364/305905731.py in <module> 4 graf_dados=df.groupby('lojas_cidade'). Count(). producto_valor.sort_values(ascending=False) 5 plt.bar(graf_dados.index,graf_dados.values) -----> 6 plt.title('Sales by Store') 7 plt.xticks(rotation=90) 8 Typeerror: 'str' Object is not callable

  • Why do you have the tag r and not python?

1 answer

-1


Check if in some code before, you are not setting the value of plt.title instead of calling it as a function.

For example, if there is a line of the type

plt.title = "Título aqui"

and subsequently a line as

plt.title("Outro título aqui")

this mistake will happen because the name title of plt was modified, becoming a string, then calling it as if it were a function produces an error.

Under normal circumstances, the name title pyplot is a function, then the line that is wrong has done nothing wrong. The actual error is in modifying the title as if it were a property. It’s a boring mistake to find, because the exception appears in a place, but the factual error is occurring before... then you are induced to look for problem where there is no.

Anyway, look in the rest of your code for lines like the first one up there, so call plt.title is not an error. It should be a function, not a string.

  • Thank you very much!!! It was that even had a =, hard to find pq the error does not show before it gets difficult right .... plt.figure(figsize=(15,5)) plt.bar(graf_dados.index,graf_dados.values) plt.title=('Recipes by Product')

  • I am glad to have helped! I recommend to mark the question as resolved. I’m also curious why they downvote, since the answer solved the problem... =/

  • 1

    I was looking for where to score, kkk Thanks Partner!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.