这就是一个小练手,请各位指点。
上代码:
import numpy as np
import matplotlib.pyplot as plt
# fixing random state for reproducbility(为再现性固定随机状态)
np.random.seed(19680801)
# The bar
x = np.random.rand(500)>0.7
barprops = dict(aspect = 'auto',cmap = 'binary',interpolation = 'nearest')
fig = plt.figure()#窗口
# a vertical barcode(垂直直方图)
ax1 = fig.add_axes([0.1,0.1,0.1,0.8])#添加轴,分别为(左,下,宽度,高度)
ax1.set_axis_off()
ax1.imshow(x.reshape((-1,1)),**barprops)
# a horizontal barcode(水平直方图)
ax2 = fig.add_axes([0.3,0.4,0.6,0.2])#分别为(左,下,宽度,高度)
ax2.set_axis_off()
ax2.imshow(x.reshape((1,-1)),**barprops)
plt.show()
matplotlib.figure.add_axes()函数的功能:用于向图形添加轴详情点击我哦
如果再seed()里面传入不同的数字那么rand()产生的随机数不同