Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip missing data on timeseries axis (candlestick or in general for timeseries charts) #1458

Open
vanheck opened this issue Nov 25, 2024 · 1 comment

Comments

@vanheck
Copy link

vanheck commented Nov 25, 2024

based on the discussion from the discourse, I would like to suggest a parameter to skip missing datetime records (remove gaps between candles). df.hvplot.ohlc(skip_missing_data=True).

original post: https://discourse.holoviz.org/t/skip-missing-data-on-timeseries-axis/6596/1

import pandas as pd
import hvplot.pandas
from bokeh.sampledata.stocks import MSFT

df = pd.DataFrame(MSFT)[60:121][["open", "high", "low", "close", "date"]]
df["date"] = pd.to_datetime(df["date"])
df = df.set_index("date")
ohlc = df.hvplot.ohlc(skip_missing_data=True)
ohlc

Actual chart:
Image

Actual workaround with a lot of unnecessary code (I think) has few disadvantages like plot is aligned on the left side instead of original df.hvplot.ohlc() is in the middle of the output cell:

import pandas as pd
import hvplot.pandas
from bokeh.sampledata.stocks import MSFT
import holoviews as hv
from bokeh.io import show

df = pd.DataFrame(MSFT)[60:121][["open", "high", "low", "close", "date"]].reset_index(drop=True)
df["date"] = pd.to_datetime(df["date"])

ohlc = df.hvplot.ohlc()
fig = hv.render(ohlc)
fig.xaxis.major_label_overrides = df["date"].dt.strftime("%m/%d").to_dict()
show(fig)

Wanted chart:
Image

The workaround is not the best. On the x axis you must manually specify the format string, DatetimeTickFormatter has much more general functionality.

@holovizbot
Copy link

This issue has been mentioned on HoloViz Discourse. There might be relevant details there:

https://discourse.holoviz.org/t/skip-missing-data-on-timeseries-axis/6596/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants