JuliaPlots/Plots.jl

[FR] Date & DateTime for ohlc

Open

#4,086 建立於 2022年2月1日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Julia (1,943 star) (381 fork)batch import
enhancementhelp wanted

描述

The plot function can take arrays of Date and DateTime as arguments, but the ohlc function throws an error when it gets such a parameter:

julia> using Plots, Dates

julia> ohlc(today()-Day(9):Day(1):today(),OHLC[(2*i,4*i,i,3*i) for i=1:10])
ERROR: MethodError: no method matching abs(::Date)
Closest candidates are:
  abs(::Complex) at C:\Users\PC\AppData\Local\Programs\Julia-1.7.1\share\julia\base\complex.jl:277
  abs(::T) where T<:Measures.Length at C:\Users\PC\.julia\packages\Measures\0Zkai\src\length.jl:33
  abs(::Unsigned) at C:\Users\PC\AppData\Local\Programs\Julia-1.7.1\share\julia\base\int.jl:179
  ...
Stacktrace:
  [1] _broadcast_getindex_evalf
    @ .\broadcast.jl:670 [inlined]
  [2] _broadcast_getindex
    @ .\broadcast.jl:643 [inlined]
  [3] getindex
    @ .\broadcast.jl:597 [inlined]
  [4] copy
    @ .\broadcast.jl:899 [inlined]
  [5] materialize
    @ .\broadcast.jl:860 [inlined]
  [6] get_xy(v::Vector{OHLC}, x::StepRange{Date, Day})
    @ Plots C:\Users\PC\.julia\packages\Plots\YAlrZ\src\recipes.jl:1517
  [7] macro expansion
    @ C:\Users\PC\.julia\packages\Plots\YAlrZ\src\recipes.jl:1548 [inlined]
  [8] apply_recipe(plotattributes::AbstractDict{Symbol, Any}, x::AbstractVector, v::AbstractVector{OHLC})
    @ Plots C:\Users\PC\.julia\packages\RecipesBase\qpxEX\src\RecipesBase.jl:289
  [9] _process_userrecipes!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline C:\Users\PC\.julia\packages\RecipesPipeline\7ijBv\src\user_recipe.jl:36
 [10] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
    @ RecipesPipeline C:\Users\PC\.julia\packages\RecipesPipeline\7ijBv\src\RecipesPipeline.jl:70
 [11] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
    @ Plots C:\Users\PC\.julia\packages\Plots\YAlrZ\src\plot.jl:208
 [12] plot(::Any, ::Vararg{Any}; kw::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}} where {V, N, names, T<:Tuple{Vararg{Any, N}}})
    @ Plots C:\Users\PC\.julia\packages\Plots\YAlrZ\src\plot.jl:91
 [13] #ohlc#432
    @ C:\Users\PC\.julia\packages\RecipesBase\qpxEX\src\RecipesBase.jl:410 [inlined]
 [14] ohlc
    @ C:\Users\PC\.julia\packages\RecipesBase\qpxEX\src\RecipesBase.jl:410 [inlined]
 [15] top-level scope
    @ .\REPL[14]:1

julia>plot(today()-Day(9):Day(1):today(),1:10)

julia>ohlc(1:10,OHLC[(2*i, 4*i, i, 3*i) for i=1:10])

It would be nice if ohlc also supported Date and DateTime as these types are very useful for stock market data and similar. This output was produced with Plots version 1.25.7, but it happens in all the versions that I have tried.

貢獻者指南