![](/img/trans.png)
[英]How to plot dates on the x-axis using Seaborn (or matplotlib)
[英]Seaborn point plot using dates as x-axis
嘗試以下操作將字符串日期轉換為datetime
對象
import time
import datetime as dt
from datetime import datetime
def dateconvert(Start_date):
try:
Start_date = int(Start_date)
Date_String = str(Start_date)
dateconv = dt.datetime.strptime(Date_String,'%YYYY-%mm-%dd').strftime('%d/%m/%Y')
return dateconv
except ValueError:
return Start_date #or '' or whatever you want to return for NULL
在我看來,Seaborn不支持datetime
作為x變量,在這種情況下,所有日期都被視為分類變量。 在這里這可能不是什么大問題,但它使我無法將回歸線擬合到點上。
我最終使用了matplotlib.errorbar
函數,並使用numpy
計算了中位數和標准差。 它似乎不是一個理想的解決方案,但它確實起作用。 (仍然在回歸趨勢線上工作,但是我現在很好。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.