InexactError when plotting Time object

I’m getting an InexactError when I run this code and I can’t figure out why

using Plots
using Dates

y = [Int(1)]
x=[Time(now())]
p=plot(x,y)

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: InexactError: Int64(6.314460000000001e11)
Stacktrace:
 [1] Int64 at .\float.jl:710 [inlined]
 [2] convert at .\number.jl:7 [inlined]
 [3] Nanosecond at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Dates\src\types.jl:33 [inlined]
 [4] timeformatter(::Float64) at C:\Users\Achu\.julia\packages\RecipesPipeline\dZsrD\src\recipes.jl:8
 [5] iterate at .\generator.jl:47 [inlined]
 [6] _collect(::Array{Float64,1}, ::Base.Generator{Array{Float64,1},typeof(RecipesPipeline.timeformatter)}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at .\array.jl:678
 [7] collect_similar(::Array{Float64,1}, ::Base.Generator{Array{Float64,1},typeof(RecipesPipeline.timeformatter)}) at .\array.jl:607
 [8] map(::Function, ::Array{Float64,1}) at .\abstractarray.jl:2072
 [9] optimal_ticks_and_labels(::Plots.Subplot{Plots.GRBackend}, ::Plots.Axis, ::Nothing) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\axes.jl:197
 [10] optimal_ticks_and_labels at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\axes.jl:128 [inlined]
 [11] get_ticks(::Plots.Subplot{Plots.GRBackend}, ::Plots.Axis) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\axes.jl:238
 [12] _update_min_padding!(::Plots.Subplot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\backends\gr.jl:926
 [13] iterate at .\generator.jl:47 [inlined]
 [14] _collect(::Array{AbstractLayout,2}, ::Base.Generator{Array{AbstractLayout,2},typeof(Plots._update_min_padding!)}, ::Base.EltypeUnknown, ::Base.HasShape{2}) at .\array.jl:678
 [15] collect_similar(::Array{AbstractLayout,2}, ::Base.Generator{Array{AbstractLayout,2},typeof(Plots._update_min_padding!)}) at .\array.jl:607
 [16] map(::Function, ::Array{AbstractLayout,2}) at .\abstractarray.jl:2072
 [17] _update_min_padding!(::Plots.GridLayout) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\layouts.jl:310
 [18] prepare_output(::Plots.Plot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\plot.jl:184
 [19] showjuno(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\output.jl:264
 [20] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::MIME{Symbol("image/svg+xml")}, ::Plots.Plot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Plots\8GUYs\src\output.jl:212
 [21] show(::IOContext{Base.GenericIOBuffer{Array{UInt8,1}}}, ::String, ::Plots.Plot{Plots.GRBackend}) at .\multimedia.jl:109
 [22] displayinplotpane(::Plots.Plot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Atom\wlPiw\src\display\showdisplay.jl:67
 [23] display(::Atom.JunoDisplay, ::Plots.Plot{Plots.GRBackend}) at C:\Users\Achu\.julia\packages\Atom\wlPiw\src\display\showdisplay.jl:118
 [24] display(::Any) at .\multimedia.jl:323
 [25] #invokelatest#1 at .\essentials.jl:712 [inlined]
 [26] invokelatest at .\essentials.jl:711 [inlined]
 [27] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\REPL.jl:161
 [28] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\REPL.jl:146
 [29] (::REPL.var"#do_respond#38"{Bool,Atom.var"#232#233",REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\REPL.jl:729
 [30] #invokelatest#1 at .\essentials.jl:712 [inlined]
 [31] invokelatest at .\essentials.jl:711 [inlined]
 [32] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\LineEdit.jl:2354
 [33] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\REPL.jl:1055
 [34] run_repl(::REPL.AbstractREPL, ::Any) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\REPL\src\REPL.jl:206
 [35] (::Base.var"#764#766"{Bool,Bool,Bool,Bool})(::Module) at .\client.jl:383
 [36] #invokelatest#1 at .\essentials.jl:712 [inlined]
 [37] invokelatest at .\essentials.jl:711 [inlined]
 [38] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at .\client.jl:367
 [39] exec_options(::Base.JLOptions) at .\client.jl:305
 [40] _start() at .\client.jl:484

What do you expect to be plotted on your x axis?

x=[string(Time(now()))]

Does this work for you?

You should file an issue with Plots.jl. Looks like there’s special handing in Plots.optimal_ticks_and_labels for Date and DateTime but not for Time.
It seems to work fine when there are a few values plotted, and they are not too tight together:

x = [now(), now() + Second(1)]
p = plot(Time.(x), 1:2)

but I can’t find a workaround for when it fails.

1 Like

Interesting. I did notice that when I had this plotting in a loop, I didn’t get the error. It displayed the graph after at least two points were on there. Will raise the issue. Thanks!