Fork me on GitHub

用matplotlib包画条形图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#条形图
#author:victor
#导入模块
import numpy as np
import matplotlib.pyplot as plt

#产生随机数
data = np.random.normal(0, 20, 1000)
bins = np.arange(-100, 100, 5) # fixed bin size

plt.xlim([min(data)-5, max(data)+5])
plt.hist(data, bins=bins, alpha=0.5)

#display the graph
plt.title('Random Gaussian data (fixed bin size)')
plt.xlabel('variable X (bin size = 5)')
plt.ylabel('count')
plt.show()

gaussian graph