【Python 绘制地震接收道集 Wigb函数】Plotting Seismic Wiggle Traces

使用Python Matplotlib绘制seismic wiggle traces

根据matlab版本的wigb.m改写。
Author(s): Xingong Li (Intseis, Integrated Seismic Solutions)
Copyright 1998-2003 Xingong
Revision: 1.2 Date: Dec/2002

代码

调用格式为wigb(data,scal,x,z,amx)
data为地震数据,数据结构为ndarray,shape:(nt,nc) (道长,道数)
scal 放缩系数
x,z 坐标轴
amx 最大值
后面四个参数是可选的
直接上代码:

import numpy as np
import matplotlib.pyplot as plt

def wigb(a=[],scal=0,x=0,z=0,amx=0):
#  WIGB: Plot seismic data using wiggles.
#
#  WIGB(a,scal,x,z,amx) 
#
#  IN  a:     地震数据 (a ndarray, traces are columns)
#      scale: multiple data by scal
#      x:     x轴(often offset)
#      z:     y轴 (often time)
#
#  Note
#
#    If only 'a' is enter, 'scal,x,z,amn,amx' are set automatically; 
#    otherwise, 'scal' is a scalar; 'x, z' are vectors for annotation in 
#    offset and time, amx are the amplitude range.
#
    if a==[]:
        nx, nz = 10, 10
        a = np.random.random((nz,nx))
        # print(a)
    nz, nx = a.shape

    trmx = np.max(np.abs(a),axis=0)
    if amx==0:
        amx = np.mean(trmx)
    if x==0:
        x = np.arange(1,nx+1,1)
        z = np.arange(1,nz+1,1)
    if scal==0:
        scal = 1
    
    if nx <=1:
        print('ERR:PlotWig: nx has to be more than 1')
        return 
    
# take the average as dx
    dx1 = np.abs(x[1:nx]-x[0:nx-1])
    dx = np.median(dx1)


    dz = z[1]-z[0]
    xmax, xmin = a.max(), a.min()

    a = a * dx / amx
    a = a * scal

    print(' PlotWig: data range [%f, %f], plotted max %f \n'%(xmin,xmax,amx))

    # set display range

    x1 = min(x) - 2.0*dx
    x2 = max(x) - 2.0*dx
    z1 = min(z) - dz
    z2 = max(z) - dz

    fig = plt.figure()
    plt.xlim([x1,x2])
    plt.ylim([z1,z2])
    plt.gca().invert_yaxis()


    zstart, zend = z[0], z[-1]

    fillcolor = [0, 0, 0]
    linecolor = [0, 0, 0]
    linewidth = 1.


    for i in range(0,nx):
        if not trmx[i]==0:
            tr = a[:,i]
            s = np.sign(tr)
            i1 = []
            for j in range(0,nz):
                if j==nz-1:
                    continue
                if not s[j]==s[j+1]:
                    i1.append(j)
            npos = len(i1)

            i1 = np.array(i1)
            if len(i1)==0:
                zadd=np.array(())
            else:
                zadd = i1 + tr[i1] / (tr[i1]-tr[i1+1])
            aadd = np.zeros(zadd.shape)

            zpos = np.where(tr>0)
            tmp = np.append(zpos,zadd)
            zz = np.sort(tmp)
            # iz =np.array(())
            # for j in range(0,len(tmp)):
            #     iz=np.append(iz,np.where(zz==tmp[j]))
            iz = np.argsort(tmp)
            aa = np.append(tr[zpos],aadd)
            iz=iz.astype(int)
            aa = aa[iz]


            if tr[0]>0:
                a0,z0=0,1.00
            else:
                a0,z0=0,zadd[0]
            if tr[nz-1]>0:
                a1,z1=0,nz
            else:
                a1,z1=0,zadd.max()
            
            zz = np.append(np.append(np.append(z0,zz),z1),z0)
            aa = np.append(np.append(np.append(a0,aa),a1),a0)

            zzz = zstart + zz * dz - dz
            plt.fill(aa+x[i], zzz+1, color=fillcolor)
            plt.plot(x[i]+[0,0],[zstart,zend],color=[1,1,1])

            plt.plot(x[i]+tr,z,color=linecolor,linewidth=linewidth)
        else:
            plt.plot([x[i],x[i]],[zstart,zend],color=linecolor,linewidth=linewidth)
    plt.show()


        

if __name__=='__main__':
    wigb()

样例

avatar

  • 12
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Python提供了多个库来实现交互式数据可视化展示,其中比较流行的有: 1. Matplotlib:一个基于Python的绘图库,可以绘制静态图像和动态图像。 2. Plotly:一个基于JavaScript的绘图库,可以生成交互式图表和报告。 3. Bokeh:一个基于JavaScript的绘图库,可以生成交互式的Web应用程序。 下面以Matplotlib和Plotly为例,介绍如何实现交互式数据可视化展示。 ## 使用Matplotlib绘制交互式数据可视化展示 Matplotlib提供了多个工具包,其中包括`mpld3`和`bokeh`,可以实现交互式数据可视化展示。 ### 使用mpld3 mpld3是一个Matplotlib的插件,可以将Matplotlib生成的静态图像转换为交互式图像。 安装mpld3: ```python pip install mpld3 ``` 以下是一个示例代码,可以绘制交互式的散点图: ```python import matplotlib.pyplot as plt import mpld3 # 生成数据 x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # 绘制散点图 fig, ax = plt.subplots() ax.scatter(x, y) # 转换为交互式图像 mpld3.show(fig) ``` 运行代码后,会显示一个包含散点图的窗口,可以使用鼠标滚轮缩放图像,也可以单击数据点查看数据。 ### 使用bokeh bokeh是一个Python的交互式可视化库,可以生成HTML、JavaScript和SVG格式的图像。 安装bokeh: ```python pip install bokeh ``` 以下是一个示例代码,可以绘制交互式的散点图: ```python from bokeh.plotting import figure, output_file, show # 设置输出文件的路径 output_file("scatter.html") # 生成数据 x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # 绘制散点图 p = figure() p.scatter(x, y) # 显示图像 show(p) ``` 运行代码后,会在当前目录下生成一个名为`scatter.html`的文件,可以用浏览器打开该文件查看交互式散点图。 ## 使用Plotly绘制交互式数据可视化展示 Plotly是一个基于JavaScript的绘图库,可以生成交互式图表和报告。Plotly提供了Python、R、MATLAB和Julia等多个语言的接口。 安装Plotly: ```python pip install plotly ``` 以下是一个示例代码,可以绘制交互式的散点图: ```python import plotly.graph_objs as go import plotly.offline as pyo # 生成数据 x = [1, 2, 3, 4, 5] y = [2, 4, 6, 8, 10] # 绘制散点图 data = [go.Scatter(x=x, y=y, mode='markers')] # 设置布局 layout = go.Layout(title='Scatter Plot') # 绘制图像 fig = go.Figure(data=data, layout=layout) # 显示图像 pyo.iplot(fig) ``` 运行代码后,会在浏览器上显示一个交互式散点图,可以使用鼠标滚轮缩放图像,也可以单击数据点查看数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值