How to do a simple scatter plot in plotly, where the y-axis is absolute?

Iโ€™m trying to do something that I imagine is very simple:

I have a dataframe that looks like the following:

                 loss             accuracy  step
0   5.723718064957251  0.10462145068317677      400
1  4.2583846196875825   0.4116140051238258     1040
2    4.13421921054081    0.433236816823228     1360
3  3.7513634213823015  0.49043952818104186     2080
4  3.5701228434157923   0.5102559911400513     2480

I want to make a scatter / line plot of the step versus the loss. In this scatter plot, I expect the loss to start high and go down.

When I use the code:

fig = px.scatter(df, x="step", y="loss", title="Loss vs Step")

I get the following output:

This output is not incorrect perse, but it is the opposite of what I want. Specifically, the y-axis is in ascending order. I want it to be in descending order, so that 0 is the bottom and 5.723 is the top. Also, instead of having the y-axis be the exact loss values, Iโ€™d prefer it to just be a regular interval. E.g, 0, 0.25, 0.5, 0.75, etc.

Is there a way to get the outcome I want? I asked ChatGPT, but couldnโ€™t get an answer from it.

Hi @vedantroy

ChatGPT is not the answer for everything? LOL

Make sure you are plotting numeric data. Check the dtype of your columns โ€˜stepโ€™ and โ€˜lossโ€™ :upside_down_face:


Thanks! Issue was my dataframe was using strings, not float/int.

1 Like