JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 356 forks source link

:native does not work with dates #1425

Open cstjean opened 6 years ago

cstjean commented 6 years ago

With plotlyjs,

image

The corresponding PlotlyJS code works fine. cc. @apalugniok

pkofod commented 6 years ago

What's :native supposed to do? In GR this prints the dates fine without it for example.

Also, it's kind of hard to copy from a picture :)

plot([DateTime(2017, 1, 1), DateTime(2017, 2, 1)], [1, 3])
plot([DateTime(2017, 1, 1), DateTime(2017, 2, 1)], [1, 3]; ticks = :native)
cstjean commented 6 years ago

See #1382

daschw commented 6 years ago

Dates and DateTimes are handled by a recipe within plots that converts them to a number via Dates.value

julia> dt = now()
2018-03-08T14:17:39.982

julia> Dates.value(dt)
63656201859982

julia> dt = now()
2018-03-08T14:18:10.296

julia> Dates.value(dt)
63656201890296

Usually Plots automatically generates ticks and corresponding tick labels (in form a Date / DateTime string) and passes this information (numerical values and tick labels) to the backends. Setting ticks = :native where it's implemented (Plotly(JS) and PyPlot, I think) tells Plots not to calculate tick positions and labels but use the backend's native algorithms for this. So in that case for Dates the backend only gets the Dates.value converted integer values without tick labels or any information that these numbers are supposed to represent dates.

daschw commented 6 years ago

The problem actually is not related to Dates and DateTimes but to the fact that ticks = :native and specifying a tick formatter do not work well together:

plot(rand(10), formatter = x -> 1000x, ticks = :native)
plot(rand(10), formatter = x -> 1000x)
apalugniok commented 6 years ago

I can fix the DateTimes issue, for Plotly at least not sure about the other backends.

It may be hard to implement the formatter with ticks = :native. I think PyPlot wants special python formatters not julia functions so it's not something you can just pass to the backend?