1 votes

TypeError: bar() missing 1 required positional argument: 'height'

I have the following problem, this is what I was coding: first I made a plot, this one if I got it right:

cuantil = Tciudades.quantile([.20,.56,.70],axis = 0) 
plt.plot(cuantil , marker="*" )
plt.xlabel("Porcentaje")
plt.ylabel("Temperatura")

Now what I want to achieve is to make a bar chart, I did something like this:

plt.xlabel("Porcentaje")
plt.ylabel("Temperatura")
plt.bar(cuantil, width = 0.1)
plt.show()

But I did not get the following error and it only throws what would be the xlab and ylab:

TypeError                                 Traceback (most recent call last)
<ipython-input-108-504078c7784f> in <module>
      1 plt.xlabel("Porcentaje")
      2 plt.ylabel("Temperatura")
----> 3 plt.bar(cuantil, width = 0.1)
      4 plt.show()

TypeError: bar() missing 1 required positional argument: 'height'

I am grateful for any help.

1voto

favcau Points 191

The error message already tells you the problem you have.

One argument is missing in the bar() method, the name of the missing argument is 'height'. .

If you search in Matplotlib documentation you will see the parameters you have to pass to bar().

One of these parameters is height .

height: float or array-like. The height(s) of the bars. Matplotlib.

Example:

plt.xlabel("Porcentaje")
plt.ylabel("Temperatura")
plt.bar(cuantil, 0.8, width = 0.1) # height = 0.8, cambiá este valor según tu necesidad.
plt.show()

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X