JuliaStats / TimeSeries.jl

Time series toolkit for Julia
Other
353 stars 69 forks source link

plotting with Plotly is semi-broken #461

Closed Moelf closed 4 years ago

Moelf commented 4 years ago

image

Plots v1.5.8
TimeSeries v0.18.0
iblislin commented 4 years ago

:man_facepalming: I need time to figure out the Plot.jl issue. I'm working on Gadfly.jl support: https://github.com/GiovineItalia/Gadfly.jl/pull/1215. Maybe you can try this branch out first

Moelf commented 4 years ago

no worries, I know Plots (recipes) can be suck to work with sometime. thx for the good work!

iblislin commented 4 years ago

Hi @Moelf , I just rewrite the plot recipe for candlestick. Could you try PR #464 out?

Moelf commented 4 years ago

image

wow, thanks for the swift reaction.

It looks like the hover tooltips is gone completely? and the x-axis is too granular I think

Moelf commented 4 years ago

let me give you this for testing:

using DataFrames, TimeSeries, Dates, Plots

m = [ 1.83    1.8708  1.83    1.84     5351.0
        1.85    1.85    1.7688  1.7701  12854.0
        1.75    1.8869  1.75    1.8201  15735.0
        1.795   1.82    1.78    1.78    24814.0
        1.76    1.8578  1.76    1.8299   6539.0
        1.8159  1.8709  1.7973  1.8309   7422.0
        1.79    1.87    1.7899  1.87    18386.0
        1.88    1.88    1.79    1.79     7768.0
        1.78    1.8     1.6785  1.75    18711.0
        1.71    1.79    1.71    1.7892  16594.0]

df = DataFrame(m, [:open, :high, :low, :close, :volume])
df.ts = (now()-Day(9)):Day(1):now()

df_ts = TimeArray(df, timestamp=:ts)

plotly()
plot(df_ts, st=:candlestick)
iblislin commented 4 years ago

It looks like the hover tooltips is gone completely?

What kind of information do you expect to show on the tooltips? Since I rewrite the recipe, there is a chance that we can decide the content of tooltips.

and the x-axis is too granular I think

well, I'm still searching about the xticks auto-shrinking method from Plots.

Moelf commented 4 years ago

if I look for inspiration on some online candle plots, for example yahool they hover a window on top left for high, low, open, close; so I guess we can default to display those 4 as well on hover.

iblislin commented 4 years ago

I update the PR and add the hover text.

also, I made the density of xticks controlled by xticks::Int . e.g.

plot(ta, st = :candlestick, xrotation = 60, xticks = 3)

newplot

iblislin commented 4 years ago

BTW, we have MarketData.yahoo in the latest version.

ta = MarketData.yahoo(:GE, YahooOpt(period1 = now() - Month(2), period2 = now()))
plot(ta, st = :candlestick, xrotation = 60, xticks = 3)

newplot

Moelf commented 4 years ago

ah, thanks, this looks much better now!

Moelf commented 4 years ago

https://plotly.com/python/candlestick-charts/

btw, while we're at it, is it possible to have the sliding window at the bottom as well? i'm looking to integrate with Dash.jl maybe it's something I need to do for Dash specifically but I really would like to use TimeSeries instead of manually construct stuff, https://github.com/plotly/Dash.jl/issues/50

iblislin commented 4 years ago

https://plotly.com/python/candlestick-charts/

JS version is here: https://plotly.com/javascript/candlestick-charts/#simple-candlestick-chart

btw, while we're at it, is it possible to have the sliding window at the bottom as well? i

If I understand correctly, in order to support native candlestick from Plotly and get the sliding window, we have to modify stuffs in Plots.plotly_series, since the JS doc of Plotly shows that the argument type: "candlestick" should go with Plots.plotly_series (the var plotattributes_out[:type]).

https://github.com/JuliaPlots/Plots.jl/blob/47590b2538b9d0387b14d46eb49e7257f904dde6/src/backends/plotly.jl#L535-L579

i'm looking to integrate with Dash.jl maybe it's something I need to do for Dash specifically but I really would like to use TimeSeries instead of manually construct stuff, plotly/Dash.jl#50

I think there are two option to get the native support of candlestick from Plotly,

  1. Add Plots native support for Plotly banckend only, and let other seriestype = :candlestick fallback to our recipe. (not sure the fallback is possible or not)
  2. Add TimeArray support for PlotlyJS.jl (but I never use that package before, also need time to figure out)
Moelf commented 4 years ago
1. Add `Plots` native support for Plotly banckend only, and let other `seriestype = :candlestick` fallback to our recipe. (not sure the fallback is possible or not)

I'm fine with using TimeSeries to extend the recipe when plotting, but I assumed this would give me the correct layout etc. when calling Plots.plotly_series on the result plot but it wasn't quite right

iblislin commented 4 years ago

I'm fine with using TimeSeries to extend the recipe when plotting, but I assumed this would give me the correct layout etc. when calling Plots.plotly_series on the result plot but it wasn't quite right

well, I'm not quite sure what you mean.

In short, the interactive sliding window of Plotly isn't possible to construct by a plot recipe. It requires some changes in Plots.plotly_series.

Moelf commented 4 years ago

ah, I see what you mean. Well, then I guess that's the extend to can do for this issue, thanks for your time and effort of fixing it!