I have a histogram which is being generated from one of the dataframe column. But I want to make line similar to histogram.
I tried to extract histogram data & plot a line chart but didn’t worked.
JavaScript
x
12
12
1
data = [
2
202.91,
3
236.04,
4
306.28,
5
6
315.83,
7
190.03
8
]
9
10
plt.hist(data)
11
plt.show()
12
This code generate a histogram, but I need a line chart which shows the trend
Advertisement
Answer
This shows the step histogram line and a line plot on it passing from the center of each bin.
JavaScript
1
6
1
import numpy as np
2
data = np.random.randn(1000)
3
n, bins, patches = plt.hist(data, histtype=u'step')
4
plt.plot(bins[:-1]+(bins[1]-bins[0])/2, n)
5
plt.show()
6