0
$\begingroup$

I was trying this simple code and am unable to find the error I made in it.

My code:

import matplotlib.pyplot as plt
import numpy as np
x = ['Python','C++','Java','Pearl','Lisp']
y = [10,8,6,4,2,1]
plt.bar(x, y,align='edge',color='orange')
plt.show()

And I am getting the error:

ValueError: shape mismatch: objects cannot be broadcast to a single shape
$\endgroup$

1 Answer 1

2
$\begingroup$

Because you're giving x with a shape of (5,) and y with a shape of (6,). Removing the last item from y to make them of equal length works without an error:

import matplotlib.pyplot as plt
import numpy as np

x = ['Python', 'C++', 'Java', 'Perl', 'Lisp']
y = [10, 8, 6, 4, 2]

plt.bar(x, y, align='edge', color='orange')
plt.show()

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.