Manoel Neto
Manoel Neto

Reputation: 11

"x and y must be the same size" issues in python, histogram graph and scatter

My code does not load because the information mentioned below appears. Remembering that my ppthdf variable is an excel file with 1 column and 100000 lines. Could you at least guess what I'm wrong?

Code:

p = np.arange(0.001, 100000, 0.01)
counts, bins = np.histogram(ppthdf['PPth'], density=True)   
plt.scatter(p, counts, s=100, c='red')
plt.show()

Problem:

ValueError: x and y must be the same size

(Actually the graph above is for plotting together with a histogram, but my histogram works, I just can't put dots on the histogram, which is the reason for the code above.)

Upvotes: 1

Views: 430

Answers (1)

Sterling
Sterling

Reputation: 442

Your arrays p and counts are different sizes.
The size of your p array is 10,000,000.
The size of counts is 100,000.

You should just do:

p = np.arange(0,100000,1)

Upvotes: 1

Related Questions