我希望看到[00:00:00, 02:00:00, 04:00:00, 06:00:00]
类似xtick的标签。pyplot和GR后端给出了相似的结果。我可以使用支持左和右yaxis的任何后端。
using DataFrames, Dates, Plots
gr(linewidth=3, markersize=4, titlefont=18, legendfont=12, guidefont=18, tickfont=14, legend=:outertopright)
df = DataFrame()
df.Time = ["0:05:02", "1:05:23", "2:05:34", "4:05:42", "5:36:01"]
df.Data = [0.0, 1.0, 0.5, 0.4, 0.1]
df.Time = Time.(df.Time, DateFormat("H:M:S"))
plot(df.Time, df.Data)
julia> plot(df.Time, df.Data, lims = :round)
julia> plot(df.Time, df.Data, ticks = 4)
julia> plot(df.Time, df.Data, lims = :round, ticks = 4)
julia> plot(df.Time, df.Data, xlims = (Time(0), Time(6)))
ERROR: MethodError: no method matching Float64(::Time)
Closest candidates are:
Float64(::UInt32) at float.jl:66
Float64(::Int128) at float.jl:94
Float64(::Float16) at float.jl:256
...
Stacktrace:
[1] (::RecipesPipeline.var"#7#8"{Symbol})(::Time) at C:\Users\nboyer.AIP\.julia\packages\RecipesPipeline\uPBKQ\src\utils.jl:201
[2] optimal_ticks_and_labels(::Plots.Subplot{Plots.GRBackend}, ::Plots.Axis, ::Nothing) at C:\Users\nboyer.AIP\.julia\packages\Plots\vsE7b\src\axes.jl:167
julia> plot(df.Time, df.Data, xticks = Time(0):Hour(2):Time(6))
上次尝试设置xticks
已关闭,但我仍然无法显示最后的勾号。有趣的是,我将范围的最后一个值设置为什么都没有关系。xticks = Time(0):Hour(2):Time(10)
产生相同的图像。
这将起作用:
plot(df.Time, df.Data,
xlims = (Dates.value(Time(0)), Dates.value(Time(6))),
xticks = Time(0):Hour(2):Time(6)
)
我觉得没有这应该是可能的Dates.value
。
最近,加入了支持Date
和DateTime
(https://github.com/JuliaPlots/Plots.jl/pull/3180),但没有Time
或TimePeriod