Doubt in plotting

k = [1,1,2,3,1,1,1,2,2,2,3,33,3,33,3,33,3,1,20,20,20,20,20,20,20]
for i in k:
While i was playing with plotting, i encountered the above code, and i actually don’t know why i got the below graph
Can anyone explain me, why I got the above graph

You don’t have to use a loop to plot. You can directly say plt.hist(k) or plt.plot(k) – is this what you wanted to do?

I got it, but my question is why we are getting the above graph when we are using loop

Ah, Ok. So it is plotting each element in the list. And it shows only 1 for each element on y-axis, this is because it is overlapping every time. Since by running a loop you are passing one element at a time. So it is not able to sum up frequency.

And because you are working on the same axes and fig and there are not subplots, everything is getting plotted on the same plot.

(btw, this is just my interpretation)

1 Like

Ya got it , i think what you said is mostly correct
thank you