본문 바로가기

Python

how to plot a histogram : matplotlib

반응형

import matplotlib.pyplot as plt
# the histogram of the data
bins = []
for i in range(-1000, 1001):
bins.append(i)

values, bins, patches = plt.hist(np.squeeze(np.array(steers)), np.squeeze(np.array(bins)), normed=False)

plt.xlabel('Steering Angle (x1000.0)')
plt.ylabel('Occurrence')
plt.grid(True)
plt.axis([-500, 500, 0, 1000])
plt.show()


# for CDF plot
cdf = []
acc_value = 0
for i in range(0, len(values)):
acc_value = acc_value + values[i]
cdf.append(acc_value)
cdf_last = cdf[len(values)-1]
cdf.append(cdf_last)

# for normalization
cdf_norm =[]
for i in range(0, len(cdf)):
cdf_norm.append(cdf[i]/cdf_last)

plt.plot(bins, cdf_norm)
plt.xlabel('Absolute Steering Angle (x1000.0)')
plt.ylabel('Cumulative Density')
plt.show()


'Python' 카테고리의 다른 글

Get file list in a directory  (0) 2017.11.30
Perspective transform  (0) 2017.11.21
How to resize an image : skimage library  (0) 2017.08.01
How to show an image : skimage library  (0) 2017.07.21
How to plot a graph : mathplotlib library  (0) 2017.07.21