plotly.js: Should remove breaks for OHLC, Candlestick
The code to reproduce is based on simple-candlestick-chart-example . The difference is:
11th, 12th are not existed in the dataset (simply because they’re weekdays/non-trading days), but candlesticks in the chart should be continued, i.e.: the breaks of 11th, 12th should be removed like what highcharts do.
This behaviour should be the default one for OHLC and Candlestick charts, otherwise it will become terrible for real world dataset.
https://codepen.io/mckelvin/pen/ygwMQz is my workaround by using tickvals
and ticktext
. But there’s another problem: nticks doesn’t work when tickmode=array as mentioned in docs, there will be too many tick labels if there’re too many ticks.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 7
- Comments: 31 (10 by maintainers)
In my opinion - I think it is an overkill to expect Plotly having to retrieve holidays/trading sessions for all instruments. You will also have to handle scenarios where there is multiple calendars (ie a GBP swap).
Most data providers already take into account non-trading days/market sessions into account. That means the data has already been cleaned/adjusted.
The only thing required would be a layout parameter to create an axis that will omit the dates for which no values exist in the timeseries.
In
v1.53.0
, users will be able to remove non-working days and non-working hours using the newaxis.breaks
API fortype: 'date'
cartesian axes.Some examples:
I’ll leave this issue open as some folks here appear to prefer the “date as categories” approach - which is another planned feature of ours.
I believe the proposed workarounds (using category or array types) break rangeselector, which requires date. Is there a workaround that keeps rangeselector functionality?
One way forward here would be to add an option to
date
axes to not-render day/hour/whatever-long periods with no data points.If you have a timeseries with even tick duration like in a candlestick, you can remove gaps by switching to a categorical xaxis & setting categoryorder like so:
https://codepen.io/nite/pen/gBxoVy?editors=0010
Worth clarifying that the xaxis then doesn’t have an even flow of time if you have varying time tick durations, eg. if you’re plotting something like a timeseries scatterplot or line plot - not an issue for grouped plots with even time ticks like candlesticks - each tick will be rendered with an even distance apart, regardless of differing durations between them.
Would be interesting how & where in the code one would be able to submit a patch @chriddyp @etpinard
This won’t be priority for us until we get a sponsor for it:
https://plot.ly/products/consulting-and-oem/
Setting the xaxis as object type seems the only viable option which is working.
From @anothar in https://github.com/plotly/plotly.js/issues/2496
Good day. Thank you for awesome library. I created this issue only because I can’t post solution in this thread. There is no need to download data about holidays for chart without breaks. Here is elegant solution for daily (or any timeframe) candlestick chart without breaks. The only problem is display text on hover. Instead of date it displays index. This can be fixed when this issue will be solved.
@etpinard Make sense but I don’t agree with the priority. IMHO, the missing feature is the largest barrier ahead of the financial users since the OHLC chart is almost the basic chart of all other high level indicator charts. If they can’t even try plotly to draw the basic chart, you can neither expect them to use it and pay for consulting.
More and more financial/trading companies start to use python stack for data analysis (at least I know Optiver is using). Plotly works so well on Jupyter. They are generous to pay for what could save time and bring profit. I’d happy to see good match between plotly and trading companies. That’s really a good reason to increase the priority. Please reconsider it.