zoukankan      html  css  js  c++  java
  • 数据分析与展示--matplotlib

    分割区域

    subplot(nrows,ncols,plot_number)

    import matplotlib.pyplot as plt
    import numpy as np
    def f(t):
        return np.exp(-t) * np.cos(2*np.pi*t)
    
    a =np.arange(0.0,5.0,0.02)
    
    plt.subplot(211)
    plt.plot(a,f(a))
    
    plt.subplot(2,1,2)
    plt.plot(a,np.cos(2*np.pi*a),'r--')
    plt.show()

     subplot2grid(GridSpec,CurSpec,colspan=1,rowsapn=1)

    colspan横向延伸

    rowsapn纵向延伸

     subplot2grid((3,3),(1,0),colspan=2)

    gridspec+subplot

    import matplotlib.gridspec as gridspec
    import matplotlib.pyplot as plt
    gs = gridspec.GridSpec(3,3)
    
    ax1 = plt.subplot(gs[0,:])
    ax2 = plt.subplot(gs[1,:-1])
    ax3 = plt.subplot(gs[1,:-1])
    ax4 = plt.subplot(gs[2,0])

    plot折线图(可以是xy坐标系,也可以是极坐标系)

    plt.plot(x,y,format_line,**kwargs)

    x可以省略,y不可以

    format_line线的颜色,风格和标记

    例如:“go-”代表绿色,O型数据标记,实线

       “b-.”代表蓝色,没有数据标记,点画线

       “*”代表自动选取颜色,*标记数据,没有线

    **kwargs绘制第二组或者更多的线时,x不可以省略

    import matplotlib.pyplot as plt
    plt.plot([0,2,4,6,8],[3,1,4,5,2])
    plt.ylabel("Grade")
    plt.axis([-1,10,0,6])
    plt.savefig('test',dpi=600)
    plt.show()

     中文显示:

    1.使用matplotlib中的rcParam

    import matplotlib

    matplotlib.rcParam['font.family']='SimHei'

    font.family  字体名称

    font.style    字体风格(斜体)

    font.size     字号

     2.在要输出的地方使用fontproperties(推荐使用)

    plt.xlabel('汉字',fontproperties='SimHei',fontsize=20)

    pie饼图(百分比)

    psd功率谱密度图

    specgram绘制谱图

    cohere绘制X-Y相关性函数

    sactter散点图

    step步阶图

    hist直方图(顺序占比)

    contour等值图

    vlines垂直图

    stem柴火图

    plot_date绘制数据日期

    引力波的图形化构建

    import numpy as np
    import matplotlib.pyplot as plt
    from scipy.io import wavfile
    
    rate_h,hstrain = wavfile.read(r'H1.wav','rb')       #速率和数据
    rate_l,lstrain = wavfile.read(r'L1.wav','rb')
    reftime,ref_H1 = np.genfromtxt('wf.txt').transpose()  #引力模型
    #reftime时间序列
    #将每一行转化为字符串,将每个字符串转化为相应的数据类型
    
    htime_interval = 1/rate_h
    ltime_interval = 1/rate_l
    
    htime_len = hstrain.shape[0]/rate_h
    htime = np.arange(-htime_len/2,htime_len/2,htime_interval)
    ltime_len = lstrain.shape[0]/rate_l
    ltime = np.arange(-ltime_len/2,ltime_len/2,ltime_interval)
    
    fig = plt.figure(figsize=(12,6))
    
    plth = fig.add_subplot(221)
    plth.plot(htime,hstrain,'y')
    plth.set_xlabel('Time (seconds)')
    plth.set_ylabel('H1 Strain')
    plth.set_title("H1 Strain")
    
    plth = fig.add_subplot(222)
    plth.plot(ltime,lstrain,'g')
    plth.set_xlabel('Time (seconds)')
    plth.set_ylabel('L1 Strain')
    plth.set_title("L1 Strain")
    
    plth = fig.add_subplot(212)
    plth.plot(reftime,ref_H1)
    plth.set_xlabel('Time (seconds)')
    plth.set_ylabel('Template Strain')
    plth.set_title("Template")
    
    fig.tight_layout()
    plt.savefig('Original.png')
    plt.show()
    plt.close(fig)
  • 相关阅读:
    超过5名学生的课
    大的国家
    shell启动时读取的配置文件
    shell中的环境变量
    chisel中pviews命令无法使用
    shell script中的$*和$@
    OS X EI Capitan 10.11.4中sudo无法起作用的解决方法
    如何判断CPU的位数
    block中无法使用C数组变量
    布尔代数
  • 原文地址:https://www.cnblogs.com/zsc329/p/9373678.html
Copyright © 2011-2022 走看看