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')
题
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.
.
The X and Y axis are assigned with values of xs and ys.
解决方案
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')