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

歡迎訪問 生活随笔!

生活随笔

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

python

python时间序列预测不连续怎么办_python – 不连续的时间序列在x轴上绘制日期

發布時間:2025/3/11 python 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python时间序列预测不连续怎么办_python – 不连续的时间序列在x轴上绘制日期 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我獲得了幾個月的數據,但在幾個月之間缺失了.如果我將整個數據集繪制在一個繪圖中(其間有很多空白空間),這看起來很奇怪.

我寫了一個小例子腳本來展示它是如何工作的(基于:

Python/Matplotlib – Is there a way to make a discontinuous axis?)

問題:我無法讓x軸使用相同的日期格式! ax或ax2都是正確的,但從來都不是.

你有什么主意嗎?

import numpy as np

import matplotlib as mpl

import matplotlib.pyplot as plt

import datetime

def getDates(startdate, enddate):

days = (enddate + datetime.timedelta(days=1) - startdate).days

dates = [ startdate + datetime.timedelta(days=x) for x in range(0,days) ]

return dates

dates1 = getDates(datetime.datetime(2013,1,1), datetime.datetime(2013,1,31))

dates2 = getDates(datetime.datetime(2013,3,1), datetime.datetime(2013,3,31))

dates = dates1+dates2

data = np.arange(len(dates))

Locator = mpl.dates.DayLocator(interval=5)

Formatter = mpl.dates.DateFormatter('%d-%m-%y')

fig,(ax,ax2) = plt.subplots(1,2,sharey=True)

fig.subplots_adjust(wspace=0.05)

fig.set_size_inches(10,3)

ax.plot(dates, data)

ax2.plot(dates, data)

ax.legend(loc=1)

ax.set_ylim( 0, 61 )

ax.set_xlim( datetime.datetime(2013,1,1), datetime.datetime(2013,1,31) )

ax2.set_xlim( datetime.datetime(2013,3,1), datetime.datetime(2013,3,31) )

labels = ax.get_xticklabels()

for label in labels: label.set_rotation(30)

labels = ax2.get_xticklabels()

for label in labels: label.set_rotation(30)

ax.spines['right'].set_visible(False)

ax2.spines['left'].set_visible(False)

ax.tick_params(right='off')

ax2.tick_params(left='off')

ax2.yaxis.tick_right()

ax.xaxis.set_major_locator(Locator)

ax.xaxis.set_major_formatter(Formatter)

ax2.xaxis.set_major_locator(Locator)

ax2.xaxis.set_major_formatter(Formatter)

plt.savefig("test.png", bbox_inches='tight')

結果:

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python时间序列预测不连续怎么办_python – 不连续的时间序列在x轴上绘制日期的全部內容,希望文章能夠幫你解決所遇到的問題。

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