方案1:
plt.xlim(dates[0] , dates[-1] )
方案2:
print("线性回归模型") fig, ax = plt.subplots() # 绘制散点图; # G1, G2 = getData2() # ax.scatter(G1[0,:], G1[1,:]) # ax.scatter(G2[0,:], G2[1,:]) #绘制直方图; data = np.random.uniform(0, 1, size = 1000) data2 = np.random.normal(0, 1, size = 1000) data3 = np.random.rand(1000) # ax.hist(data,bins=20) #随机采样 # ax.hist(data2,bins=30) #正太分布,均值为0,方差为1 ax.hist(data3,bins=20) #随机分布 #固定X轴、Y轴的范围 ax.set_ylim(ymin = 0, ymax = 130) ax.set_xlim(xmin = -5, xmax = 5) fig.show()