做策略時,經常會畫到時間順序圖表,PyPlot庫中有一個plot_date函數,可以滿足這個需求。
函數:
plot_date(x, y, fmt='bo', tz=None, xdate=True, ydate=False, **kwargs)
其中,x and/or y can be a sequence of dates represented as float days since 0001-01-01 UTC.
具體應用如下:
一、畫一個日期順序圖表
using PyPlotx = [DateTime(2013,10,4):Dates.Day(5):DateTime(2014,10,4,1);] # Generate time arrayy = rand(length(x),1)p = plot_date(x,y,linestyle="-",marker="None",label="Test Plot");
問題:如果要不同的X軸格式,如何調整設定。
(Dec-2013=>2013-12)
二、兩張圖
using PyPlot# datex = [DateTime(2013,10,4):Dates.Day(5):DateTime(2014,10,4,1);] # Generate time arrayy1 = rand(length(x),1)y2 = y1.+ 0.2#x =Dates.format(x,"YY-MM-DD");p = plot_date(x,y1,fmt ="o",linestyle="-",marker="None",label="Test Plot");P2= plot_date(x,y2,fmt ="o",linestyle="-",marker="None",label="Test Plot");
三、畫一個分時順序圖表
x = [DateTime(2013,10,4):Dates.Minute(20):DateTime(2013,10,5);] y =rand(length(x),1);p =plot_date(x,y,linestyle="-",marker="None",label="Test Plot")