• 画水深图


    import numpy as np
    import pandas as pd
    import datetime
    import re
    import time
    import glob
    import copy
    import matplotlib.dates as mdate
    from scipy.interpolate import make_interp_spline
    from scipy.interpolate import interp1d
    from matplotlib import pyplot as plt
    dateparse = lambda date: pd.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
    df =pd.read_csv(r'.17-20.csv',encoding='utf-8',parse_dates=['date'],date_parser=dateparse)

    s = np.array(df['h1'])
    d = len(s)
    helper = pd.DataFrame({'date': pd.date_range(df['date'].min(), df['date'].max(), freq='0.125H')})
    d1 = len(helper['date'])
    a = np.linspace(0,d,d)
    a_1 = np.linspace(0,d,(d1))
    p = make_interp_spline(a,s)(a_1)
    p1 = pd.Series(p)
    print(p1)
    df1 = pd.merge(df,helper,on='date',how='outer').sort_values('date')
    df1.reset_index(inplace=True,drop=True)
    df1['h2'] =p1
    print(df1)
    df1.set_index(['date'],inplace=True)
    df.set_index(['date'],inplace=True)

    plt.rcParams['font.sans-serif'] = 'Simhei'
    fig = plt.figure(figsize=(16, 8))
    # ax1 = fig.add_subplot(2,2,1)
    # ax1.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))
    # plt.xticks(pd.date_range(df.index[0],df.index[-1],freq='0.25D'),rotation=90)
    # ax1.plot(df.index, df['h1'], color='g', label='深度')
    # # plt.show()
    ax2 = fig.add_subplot(111)
    ax2.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))
    plt.xticks(pd.date_range(df1.index[0],df1.index[-1],freq='0.125D'),rotation=45)
    ax2.plot(df1.index, df1['h2'], color='g', label='深度')
    ax2.plot(df.index, df['h1'], color='r', label='深度')
    plt.show()
  • 相关阅读:
    Toolbar Painter 工具条制作
    编程实现Windows瞬间关机
    如何在应用程序中修改本地环境变量
    据磁力链获得BT种子
    熟练使用NTFS的文件链接技术
    js中实现页面跳转
    keychain 多应用共享数据
    得到bundle seed id
    shell 基础 $(cd `dirname $0`;pwd)
    解决iOS应用内购买报错:invalidProductIdentifiers
  • 原文地址:https://www.cnblogs.com/chenyun-delft3d/p/13645980.html
Copyright © 2020-2023  润新知