X Axis Datetime Display Not Rendering Full Format for Smaller Range

I am running into the same issue documented in

I would like to display the full date on every x axis ticker, (e.g. 10/10/2021 14:51:13),
However, when the range of the graph I use is too small (my x axis spans approximately 30 seconds worth of data), it does not render the full date, only the seconds.

I am using the datetimetickformatter, which does not remedy the issue.

plot.xaxis.formatter = DatetimeTickFormatter(days="%d-%b-%Y", hours="%H:%M", seconds="%S")

I would like to know if this is even possible to fully format the x axis to show the entire date. If not, is there a way I can display the missing date information on the graph separately in a single location?

For context, I am using a bokeh server with a callback that is streaming new data to the plot. So the issue I am running into with a new method I am trying, is I am putting a text glyph with the missing date information on the plot at the newest x,y coordinates. However, this makes the plot messy because the text glyph jumps around when new data is streamed. I have also tried this using a LabelSet but have the same issue. Is there a way to mount a glyph to a specific location, maybe outside the plot, so it is not dependent on the streaming x,y coordinates, but also update the data with a columndatasource object? Or is there another way to accomplish this? I need some way to display the current date and time on the plot so there is context for what day, hour, and minute it is since the plot only shows seconds.

text_source = ColumnDataSource(df)
glyph = Text(x="Time", y="y", text="Time")
plot.add_glyph(text_source, glyph)

def callback():
    text_source.data = ColumnDataSource.from_df(new_df)

Hi @lemgog

Based on the description of your problem and the referenced stackoverflow post, I believe the issue is a misunderstanding of how the datetime tick-formatter works.

When you specify arguments, e.g.

you are saying how the tick labels should be formatted when the range of the associated axis is on that timescale, days in this example.

In your case, where the x-axis time interval is on the order of half-minute/tens-of-seconds, you need to explicitly set the format for minsec and seconds explicitly. And if there is interactive capability to zoom in or out, you might want to set the other timescale values too. Here’s an example setting all the timescales to the same format, which might or might not work in your use case, but conveys the concept

p.xaxis.formatter = DatetimeTickFormatter(years="%d/%m/%Y %H:%M:%S",
                                          months="%d/%m/%Y %H:%M:%S",
                                          days="%d/%m/%Y %H:%M:%S",
                                          hours="%d/%m/%Y %H:%M:%S",
                                          hourmin="%d/%m/%Y %H:%M:%S",
                                          minutes="%d/%m/%Y %H:%M:%S",
                                          minsec="%d/%m/%Y %H:%M:%S",
                                          seconds="%d/%m/%Y %H:%M:%S",
                                          milliseconds="%d/%m/%Y %H:%M:%S",
                                          microseconds="%d/%m/%Y %H:%M:%S")

Thank you so much! That worked perfectly, I understand how it works now that you have to define it for every view. That makes a lot more sense.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.