-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Set OHLC x-axis tooltip to datetime format #1493
base: main
Are you sure you want to change the base?
Conversation
Azaya89
commented
Feb 6, 2025
•
edited
Loading
edited
- fixes OHLC hover text date format bug #1487
- Added tests
Ah, @%#$! |
assert '{%F}' in x_tooltip | ||
formatter_key = '@' + x_label | ||
formatter = hover_tool.formatters | ||
assert formatter.get(formatter_key) == 'datetime' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert formatter.get(formatter_key) == 'datetime' | |
assert formatter[formatter_key] == 'datetime' |
@@ -32,3 +32,39 @@ def test_ohlc_hover_cols_all(): | |||
tooltips = segments.opts.get('plot').kwargs['tools'][0].tooltips | |||
assert len(tooltips) == len(df.columns) + 1 | |||
assert tooltips[-1] == ('Volume', '@Volume') | |||
|
|||
|
|||
def test_ohlc_date_tooltip_format(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another test could be added with a DataFrame whose date column isn't the index.
@@ -2630,15 +2630,23 @@ def ohlc(self, x=None, y=None, data=None): | |||
seg_cur_opts, seg_compat_opts = self._get_compat_opts('Segments') | |||
tools = seg_cur_opts.pop('tools', []) | |||
if 'hover' in tools: | |||
x_data = data[x] if x in data.columns else data.index | |||
if pd.api.types.is_datetime64_any_dtype(x_data): | |||
x_tooltip = f'@{x}{{%F}}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments on %F
:
- I can never remember what these sort of format codes mean :) I looked up Bokeh's documentation and think I found the place where it's documented as part of the
DateFormatter
.%F
is a strftime format code Equivalent to %Y-%m-%d (the ISO 8601 date format). Could you add a little comment like%F: strftime code for %Y-%m-%d
? - Are OHLC plots limited to daily time series? Asked ChatGPT that says it's the main use case but hourly also happens ("mainly day traders and algorithmic traders focusing on short-term price movements"). What do you think about using instead
%F %T
, equivalent to%Y-%m-%d %H:%M:%S
?