zoukankan      html  css  js  c++  java
  • matplotlib之histograms

    直方图笔记

    1. 画直方图。

    # create 2x2 grid of axis subplots
    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex=True)
    axs = [ax1,ax2,ax3,ax4]
    
    # draw n = 10, 100, 1000, and 10000 samples from the normal distribution and plot corresponding histograms
    for n in range(0,len(axs)):
        sample_size = 10**(n+1)
        sample = np.random.normal(loc=0.0, scale=1.0, size=sample_size)
        axs[n].hist(sample)
        axs[n].set_title('n={}'.format(sample_size))

    2.设置hist的bin值

    如何选择bin的数目。

    http://users.stat.umn.edu/~gmeeden/papers/hist.pdf

    # repeat with number of bins set to 100
    fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex=True)
    axs = [ax1,ax2,ax3,ax4]
    
    for n in range(0,len(axs)):
        sample_size = 10**(n+1)
        sample = np.random.normal(loc=0.0, scale=1.0, size=sample_size)
        axs[n].hist(sample, bins=100)
        axs[n].set_title('n={}'.format(sample_size))

    直方图显示

    3.

    plt.figure()
    Y = np.random.normal(loc=0.0, scale=1.0, size=10000)
    X = np.random.random(size=10000)
    plt.scatter(X,Y)

    4.使用matplotlib.gridspec作图

    # use gridspec to partition the figure into subplots
    import matplotlib.gridspec as gridspec
    
    plt.figure()
    gspec = gridspec.GridSpec(3, 3)
    
    top_histogram = plt.subplot(gspec[0, 1:])
    side_histogram = plt.subplot(gspec[1:, 0])
    lower_right = plt.subplot(gspec[1:, 1:])

    5. hist的orientation设置。

    Y = np.random.normal(loc=0.0, scale=1.0, size=10000)
    X = np.random.random(size=10000)
    lower_right.scatter(X, Y)
    top_histogram.hist(X, bins=100)
    s = side_histogram.hist(Y, bins=100, orientation='horizontal')

    6. clear()函数

    # clear the histograms and plot normed histograms
    top_histogram.clear()
    top_histogram.hist(X, bins=100, normed=True)
    side_histogram.clear()
    side_histogram.hist(Y, bins=100, orientation='horizontal', normed=True)
    # flip the side histogram's x axis
    side_histogram.invert_xaxis()

    7.坐标范围限制

    # change axes limits
    for ax in [top_histogram, lower_right]:
        ax.set_xlim(0, 1)
    for ax in [side_histogram, lower_right]:
        ax.set_ylim(-5, 5)

    The Safest Way to Get what you Want is to Try and Deserve What you Want.
  • 相关阅读:
    嗨分享-前端技术-帝国CMS手机站修改列表分页(sysShowListMorePage)
    外观模式
    模版方法模式
    原型模式(克隆)
    策略模式
    装饰模式和代理模式
    设计原则
    工厂模式
    反射机制
    vmware RHEL6.x 开启FTP和TELNET服务--root权限
  • 原文地址:https://www.cnblogs.com/Shinered/p/9530290.html
Copyright © 2011-2022 走看看