日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python x轴显示指定时间刻度

發布時間:2023/12/20 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python x轴显示指定时间刻度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

將x軸設置為時間軸

  • 將x軸設置為時間軸
  • 顯示指定日期
  • 注意事項:

    在對x軸進行時間轉換時需要注意:
    - datetime.date2num():是從1,1,1開始計數,單位是天
    - time.mktime():是從1970.1.1開始計數,單位是秒

    實例

    # 摘取自ww3項目Figure_area_average.py import time, datetime, calendar import numpy as np import matplotlib.pyplot as plt import matplotlib.dates as dt import matplotlib.ticker as ticker from matplotlib.dates import DateFormatter, MONDAY, MonthLocator, YearLocator from Package_Read.Filter_tools import * # 畫圖 fig = plt.figure(figsize=[9, 5]) ax = fig.add_subplot(1, 1, 1)formatter = DateFormatter('%Y/%m/%d') time1 = datetime.date(1970, 1, 1) time2 = dt.date2num(time1) timex0=timex timex = timex/24/3600 + time2 ax.plot_date(timex[2:-1], dhf[2:-1], '-',label='high', alpha=1) ax.plot_date(timex[2:-1], dbf[2:-1], '-',label='band', alpha=1) ax.plot_date(timex[2:-1], dlf[2:-1], '-',label='low', alpha=1) # ax.set_alpha = 0.8 ax.xaxis.set_major_formatter(formatter) ax.yaxis.grid(True) # 顯示x刻度網格# 設置x軸時間刻度 yeardays=YearLocator() # 獲取每年第一日數據 mondays=MonthLocator() # 獲取每月第一日數據 locate=MonthLocator(range(1, 13), bymonthday=1, interval=6) # 獲取每3個月第一日數據ax.xaxis.set_major_locator(locate) # 設定主刻度 ax.xaxis.set_minor_locator(mondays) # 設定次刻度 # autodates = dt.AutoDateLocator() # 自動顯示x軸時間刻度 # ax.xaxis.set_major_locator(autodates) # 設置時間間隔 ax.xaxis.set_major_formatter(formatter) # 設置時間顯示格式 fig.autofmt_xdate() # 自動旋轉xlabel # ax.yaxis.set_ticks_position('both') # 在圖像左右兩側顯示y軸刻度 formatter_y=ticker.PercentFormatter(xmax=100) ax.yaxis.set_major_formatter(formatter_y) ax.legend(loc='upper right', shadow=False) # ax.set_xlabel('Time (year/month/day)') ax.set_ylabel('$\int(U_{air}-U_{oc})/U_{oc}dt$') ax.set_xlim(timex[0], timex[-1]) ax.set_title(f'Waves effect on surface current\n 'f'lon:{lon1}-{lon2} lat:{lat1}-{lat2}')fig.show() fig.savefig(fig_file,dpi=300)

    總結

    以上是生活随笔為你收集整理的python x轴显示指定时间刻度的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。