Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plotting histogram as line graph in matplot using x and y values in python

I have two input values for X-axis and Y-axis. I would like to plot a histogram as a line graph. An example is provided in the attached image. I am not able to plot a histogram using these values.

ys = [0.21428571428571427, 0.14285714285714285, 0.047619047619047616, 0.11904761904761904, 0.09523809523809523, 0.09523809523809523, 0.023809523809523808, 0.09523809523809523, 0.11904761904761904, 0.047619047619047616]

xs = [0,1,2,3,4,5,6,7,8,9]

I tried

plt.hist(xs,ys)
plt.show()

but it failed.

I am interested in a graph like the following, preferably with and without the line on the histogram.

enter image description here.

The X and Y axis are assigned with values of xs and ys.

like image 954
brain storm Avatar asked Jun 21 '26 22:06

brain storm


1 Answers

The function you need is bar. Here's a minimal example:

>>> bar(xs, ys, width=1, align='center', color='brown')
>>> plot(xs, ys, color='purple', lw=2, marker='s')

like image 88
Lev Levitsky Avatar answered Jun 24 '26 12:06

Lev Levitsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!