Black Lives Matter. Please consider donating to Black Girls Code today.
https://www.blackgirlscode.com

How to stretch line over the graphics end?

I need to extend line at the end of graphics area, that is made with 2 DataFrame points with DatetimeIndex as on screen below:

How to do that? With math I would calculate where line exactly hits x axis, buy it’s impossible, because you can not measure distance between Jan 4 and Jan 5, because it’s 1 day.

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({
    'score':[30, 60, 38, 10, 50, 70, 40],
    'date':['2000-01-01', '2000-01-02', '2000-01-03', '2000-01-04', '2000-01-05', '2000-01-06', '2000-01-07'],
})
df['date'] = pd.to_datetime(df['date'])

fig = go.Figure()
fig.add_shape(
    dict(
        type="line",
        x0=df.iloc[1]['date'],
        y0=df.iloc[1]['score'],
        x1=df.iloc[2]['date'],
        y1=df.iloc[2]['score'],
        line=dict(
        color="RoyalBlue",
        width=3
    )
))

fig.add_trace(
    go.Scatter(
        mode='markers',
        x=df['date'],
        y=df['score'],
        marker=dict(
            color='LightSkyBlue',
            size=12,
            line=dict(
                color='MediumPurple',
                width=4
            )
        ),
    )
)

fig.update_xaxes(tickmode='auto',)
fig.show()

You can convert your dates to timestamps to compute the x-intersect in seconds since epoch (1st Jan 1970). Once you have this value, convert it back to a datetime to plot it on your graph.

Thank you for reply. Is this the only way to solve my problem? Calculate where line hits x axis when y=0 and do such operations is very hard core, maybe there is simple solution?
Also, line can have small angle, so on graphics it will not hit x axis

I don’t think there is a simple way to stretch a line to infinity (nor to the edges of the figure) with plotly.