Open MarcSkovMadsen opened 10 months ago
This is because the xformatter
string is not a printf formatted string but a datetime one, this is also what is mentioned in the docstring.
I can be recreated in HoloViews with hv.Curve(data, "date", "close").opts(xformatter="%d-%Y")
. The wrap_formatter
seems to be the function to change if you want to add more logic around datetime formatted.
Doing a little more digging on this one. The printf style refers to a family of functions in C to format strings, in Python this is now used to refer to the old string format as in 'pi %5.3f.' % math.pi
. When you pass a string to xformatter
in hvPlot/HoloViews, it's assumed in this format and a PrintfTickFormatter will be created, the implementation doesn't validate that the format matches on the Python side, it uses the sprintf.js library to format and something is going to fail while rendering (that should be better handle on BokehJS' side?).
What you tried to use is Python's strftime format, that is not included in the printf-style format, but is in .format()
and f-string:
What I'd like to know is what you were trying to achieve by setting xformatter
, as I'd assume that when you zoom in you'd still want the x-ticks to scale to higher resolution values (months->days->hours...).
The DatetimeTickFormatter
is the default formatter used for a datetime axis. You can pass a new instance if you wish to customize it. You can for instance update how ticks are formatted at the days level with DatetimeTickFormatter(days="%Y/%m/%d")
:
Or you can set a context which is a relatively new feature, quite unknown but very useful! For instance with DatetimeTickFormatter(context=RELATIVE_DATETIME_CONTEXT())
:
I think the only reasonable thing we can do is improve the docs, pointing to the right places and adding some examples.
Thx. What i am trying to achieve is to enable the ChatBot to set the xformatter also for dates.
It is told that the xformatter is a string and supports printf style formatting. Then it suggests the formatting that fails.
It sounds to me like printf style is obsolete and something modern that a Human or an AI would know how to use should be supported instead?
We still use printf formatting for numbers even with the new Python format: f"{1:0.2f}"
.
What is happening in Python uses the __format__
, to determine how it should format the object. E.g. for datetime it will use strftime
.
I've been working on a chat interface for hvPlot. Its already available at Panel-Chat-Examples.
According to https://hvplot.holoviz.org/user_guide/Customization.html the
xformatter
argument should support astr
argument.But when I try, the plot does not show and I see errors raised in the browser console.
If I don't use the
xformatter
, then the plot shows.