function plot!(df::DataFrame, colx::Symbol, coly::Symbol)
    plotspecs = "u 1:2 w l tit '$(string(coly))'"
    datos = [string.(df[!, colx]), df[!, coly]]
    PlotElement(data = Gnuplot.Dataset(datos), plot = plotspecs)
end

function plot!(df::DataFrame, colx::Symbol, coly::Symbol, lc::Symbol)
    plotspecs = "u 1:2 w l lc '$(string(lc))' tit '$(string(coly))'"
    datos = [string.(df[!, colx]), df[!, coly]]
    PlotElement(data = Gnuplot.Dataset(datos), plot = plotspecs)
end

function timeformat(date::String)
    if length(date) == 10
        timefmt = "%Y-%m-%d"
        pfmt = "%Y-%m-%d"
        return timefmt, pfmt
    elseif length(date) == 19
        timefmt = "%Y-%m-%dT%H:%M:%S"
        pfmt = "%m-%d %H:%M"
        return timefmt, pfmt
    else
        print("""Please make sure your Date format
            is "yyyy-mm-dd" or "yyyy-mm-dd HH:MM:SS" """)
        return false, false
    end

end

function plot(df::DataFrame, colx::Symbol, coly::Symbol;
        lc = :black, title = "", lw = 1, rot_xtics = -45, leg_p = "t")

    date = string.(df[1, colx])
    timefmt, pfmt = timeformat(date)

    plotspecs = "u 1:2 w l lw $(lw) lc '$(string(lc))' tit '$(string(coly))'"
    cmds=["set xdata time", "set timefmt '\"$(timefmt)\"'",
        "set format x '$(pfmt)'", "set xtics rotate by $(rot_xtics)",
        "set rmargin 7", "set key $(leg_p)", "set title '$(title)'"]
    datos = [string.(df[!, colx]), df[!, coly]]
    out = Vector{Gnuplot.PlotElement}()
    push!(out, PlotElement(cmds = cmds,
            data = Gnuplot.Dataset(datos), plot = plotspecs))
    return out
end
function plot(df::DataFrame, colx::Symbol; ini_date ="" , end_date = "",
         box_color="black", leg_p = "b", rot_xtics = -45)

    tempo = string.(df[!, colx])
    yopen = df[!, :open]
    ylow  = df[!, :low]
    yhigh = df[!, :high]
    yclose = df[!, :close]

    xmin, xmax = minimum(tempo), maximum(tempo)
    xmin2 = ini_date == "" ? xmin : ini_date
    xmax2 = end_date == "" ? xmax : end_date

    date = string.(df[1, colx])
    timefmt, pfmt = timeformat(date)

    @gp "set xdata time" "set timefmt '\"$(timefmt)\"'" :-
    @gp :- "set format x '$(pfmt)'" "set xtics rotate by $(rot_xtics)" :-
    @gp :- "set rmargin 7" "set key $(leg_p)" :-
    @gp :- """set xrange [\'"$(xmin2)\"':\'"$(xmax2)\"']""" :-
    @gp :- "set rmargin 7" "set key $(leg_p)" :-
    @gp :- tempo yopen ylow yhigh yclose "u 1:2:3:4:5 w candlesticks whiskerbars 0.5 lc '$(box_color)' tit 'open < close'" :-
    @gp :- [tempo[1]] [minimum(ylow)] "u 1:2 with boxes lt 1 lw 0 lc '$(box_color)' fs solid 1 title 'close < open'"
end
function plot(df::DataFrame, colx::Symbol, coly::Symbol, color::String, cmap::Symbol;
         lcol = "black", α = 1, lw = 1, rot_xtics=-45, leg_p = "t" )

    tempo, yvals = string.(df[!, colx]), df[!, coly]
    xmin, xmax = minimum(df[!, colx]), maximum(df[!, colx])
    ymin, ymax = minimum(yvals), maximum(yvals)

    customPalette = "set palette defined (0 'white', 1 'white', 2 '$(color)', 3 '$(color)', 4 '$(color)', 5 '$(color)')"
    transparency = "set style fill transparent solid $(α) noborder"
    areaColor = "set colorbox back user origin graph 0, graph 0 size graph 1, graph 1"
    customPalette = color == "" ? Gnuplot.palette(cmap) : customPalette

    date = string.(df[1, colx])
    timefmt, pfmt = timeformat(date)

    @gp "set xdata time" "set timefmt '\"$(timefmt)\"'" :-
    @gp :- "set format x '$(pfmt)'" "set xtics rotate by $(rot_xtics)" :-
    @gp :- """set xrange [\'"$(xmin))\"':\'"$(xmax)\"']""" :-
    @gp :- yrange = (ymin - 0.1*(ymax-ymin), ymax+0.1*(ymax-ymin)) :-
    @gp :- "set rmargin 7" "set key $(leg_p)" :-
    @gp :- tempo yvals yvals "u 1:2:3 w l notit lw 0 dt 1 lc palette" :-
    @gp :- customPalette transparency areaColor "set tics front" "unset cbtics" :-
    @gp :- tempo yvals "u 1:2 w filledcurves x2 fc rgb 'white' notit fs solid noborder" :-
    @gp :- tempo yvals "u 1:2 w l tit '$(string(coly))' lc '$(lcol)' lw $(lw)"
    @gp
end
function plot(iniDate::String, lastDate::String, ypos; label = "", lw = 1)
    data = [[iniDate, lastDate], [ypos, ypos]]
    out = Vector{Gnuplot.PlotElement}()
    plotspecs = "u 1:2 w l lw $(lw) t '$(label)'"
    push!(out, PlotElement(
            data = Gnuplot.Dataset(data), plot = plotspecs))
    return out
end
function plot(iniDate::String, lastDate::String, ypos, lc; label = "", lw = 1)
    data = [[iniDate, lastDate], [ypos, ypos]]
    out = Vector{Gnuplot.PlotElement}()
    plotspecs = "u 1:2 w l lw $(lw) lc '$(string(lc))' t '$(label)'"
    push!(out, PlotElement(
            data = Gnuplot.Dataset(data), plot = plotspecs))
    return out
end

function hline_at(y; color = "black", lw = 2)
    "set arrow front from graph 0, first $(y) to graph 1, first $(y) nohead lc rgb '$(color)' lw $(lw)"
end
