0

I am trying to use plotly with streamlit. I want to add error bars to my data. The y axis is a date, and I have start and end date, therefore, I compute the timedelta. Then, I use total_seconds and multiply by 1000 to get the error. See my code:

    df["date_finish"] = pd.to_datetime(df.date_finish)
    df["date_start"] = pd.to_datetime(df.date_start)
    df["date_delta"] = (df["date_finish"] - df["date_start"]) / 2
    df["center_date"] = df["date_start"] + df["date_delta"]
    df["date_error"] = df.date_delta.dt.total_seconds() * 1000
    fig = px.scatter(
        df,
        x="my_data",
        y="center_date",
        color="categories",
        error_x="data_error",
        error_y="date_error",
    )
    st.plotly_chart(fig)

This is, however, not working, neither does it work to use timedelta (as it should work ideally). What am I doing wrong?

I have checked, and this is my error date values:

df.date_error.describe()
count    6.300000e+01
mean     3.099296e+06
std      2.830500e+05
min      2.801949e+06
25%      2.813138e+06
50%      3.113366e+06
75%      3.405682e+06
max      4.026567e+06
3
  • What do you mean by it didn't work ? can you provide a toy dataset to test your code ? Commented Jan 26 at 9:05
  • No error bars, as if the parameter was none existent. Commented Jan 27 at 10:02
  • Have you tried outside of streamlit with fig.show() ? a few rows of your data is needed. Commented Jan 27 at 21:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.