'Plotly - How to plot discrete timestamps in a timeline

I have one pandas dataframe with begin and end timestamps. I managed to plot this data as time ranges using:

import plotly.express as ex

passes, messages = init()

pass_fig = ex.timeline(passes, x_start="begin", x_end='end', y='n')

which yields something like this:

Now, on top of this graph, i want to add discrete timestamps from another dataframe. I would like to show these timestamps as discrete lines, but I am not quite sure how to achieve this. My first approach was to "extend" the timestamps to a timerange of 1 minute, so I can plot them the same way I plotted the first figure:

messages["transmitted_at_p1"] = messages["transmitted_at"] + timedelta(minutes=1)

transmitted_fig = ex.timeline(messages, x_start="transmitted_at", x_end="transmitted_at_p1", y="n", color="n", color_discrete_map={"n": "red"})

pass_fig.add_trace(transmitted_fig.data[0])

which yields this: The problem now is that these timestamps are not discrete anymore and they tend to overlap each other, and when zooming out, they are barely visible.

Is there a(n easy) way to plot timestamps as lines, so that a single line has a constant pixel width, independent of the zoom level?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source