[Python] plot time for scatter chart in log scale - plotly

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I've got a wide range of values in seconds that I want to display in log scale. It works fine if i plot the raw data in seconds. But I'm trying to convert the y-axis to timestamps and keep the log scale.

    df = pd.DataFrame({
    'Position':(1,2,3,4,5,6,7,8,9),
    'Value':(1,20,821,2300,4500,30000,405600,1023764,11256400),
    })

    # works
    fig = px.scatter(x=df['Position'], y=df['Value'], log_y="True")


    When trying to change the y-axis to datetime, the values aren't correct. When trying to insert the log scale, the values don;t appear at all.

    fig = px.scatter(x=df['Position'], y=pd.to_datetime(df['Value'], unit = 's'))
    fig = px.scatter(x=df['Position'], y=pd.to_datetime(df['Value'], unit = 's'), log_y="True")


    The output y-axis should range from 0 to 130 days, 6 hours, 46 mins, 40 secs. I'm not fussed about being specific here, the broad range is fine.

    Continue reading...

Compartilhe esta Página