bianjing

绘制简单的正太分布图

    mu = 0
    sigma = 1
   matplotlib.rcParams[\'font.sans-serif\'] = [u\'SimHei\'] # FangSong/黑体 FangSong/KaiTi
   matplotlib.rcParams[\'axes.unicode_minus\'] = False # 符号不做特殊处理
x = np.linspace(mu - 3 * sigma, mu + 3 * sigma, 50)
    y = np.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (math.sqrt(2 * math.pi) * sigma)
    print x.shape
    print \'x = \n\', x
    print y.shape
    print \'y = \n\', y
    # plt.plot(x, y, \'ro-\', linewidth=2)
    # \'r-\':红色的线,‘go’: 绿色的圆圈取表示,linewidth=2:线的宽度为2,markersize=8:圆圈的大小为8
    plt.plot(x, y, \'r-\', x, y, \'go\', linewidth=2, markersize=8)
    plt.grid(True)
    plt.title(u\'Guass正太分布\')
    plt.show()

sigma = 1 平方差,mu = 0 均值

python2 会出现中文显示的问题,在图形显示时加上下面两句,就可以正确显示 

  matplotlib.rcParams[\'font.sans-serif\'] = [u\'SimHei\'] # FangSong/黑体 FangSong/KaiTi

  matplotlib.rcParams[\'axes.unicode_minus\'] = False # 符号不做特殊处理

 

分类:

技术点:

相关文章:

  • 2021-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-04-23
  • 2021-11-06
  • 2021-09-24
  • 2021-10-30
猜你喜欢
  • 2022-01-15
  • 2021-12-01
  • 2021-05-13
  • 2021-11-04
  • 2022-12-23
  • 2021-12-31
  • 2021-10-29
相关资源
相似解决方案