Pregunta

I want to plot the following:

x = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
y = [10, 20, 1, 8, 7, 2, 3, 7, 11]

as a bar chart (the bars width can be any number as long as they are visible)

when I do:

plt.figure()
plt.bar(x, y)

I get:

TypeError: cannot concatenate 'str' and 'float' objects

Why? How can I see a bar chart for this?

¿Fue útil?

Solución

The error means that you're passing the wrong type.

A guess, assuming this is pyplot, the bar command has the arguments:

left, height, width=0.8, bottom=None, hold=None, **kwargs

You're passing an array of strings for 'left' but you need an array of scalar numeric types there. 'left' is not label, it's coordinate.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top