Skip to content

plotly.express.line uses group's row number? instead of desired y value #5321

@bfletcherjohnson

Description

@bfletcherjohnson

This is, hopefully, a more understandable MRE of issue 5317. In Jupyter notebook, plotly.express, px.line(x = date, y = APY ....) does NOT use APY as the y coordinate, but appears to use the index. matplotlib gives the correct plot. If I copy the code to spyder, I get the correct plot from plotly (and matplotlib). In Jupyter Notebook, if you print(fig), 'x' shows up fine buy 'y' is unintelligible (to me)

'y': {'bdata': ('hJ7Nqs/Vpj9iEFg5tMimP9zXgXNGlK' ...

CODE is below.

`import plotly.express as px
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick

Date = ["12 Aug 2025 12:00", "5 Aug 2025 12:00", "29 Jul 2025 12:00", "22 Jul 2025 12:00", "15 Jul 2025 12:00",
"8 Jul 2025 12:00", "1 Jul 2025 12:00", "24 Jun 2025 12:00", "17 Jun 2025 12:00", "10 Jun 2025 12:00",
"3 Jun 2025 12:00", "27 May 2025 12:00", "20 May 2025 12:00", "13 May 2025 12:00", "6 May 2025 12:00",
"29 Apr 2025 12:00", "22 Apr 2025 12:00", "15 Apr 2025 12:00", "8 Apr 2025 12:00", "1 Apr 2025 12:00",
"25 Mar 2025 12:00", "18 Mar 2025 12:00", "11 Mar 2025 12:00", "4 Mar 2025 12:00"]
date = pd.to_datetime(Date)

APY = [0.0446, 0.0445, 0.0441, 0.0439, 0.0439, 0.0440, 0.0415, 0.0421, 0.0423, 0.0433, 0.0437, 0.0438,
0.0438, 0.0438, 0.0440, 0.0438, 0.0440, 0.0441, 0.0440, 0.0438, 0.0437, 0.0438, 0.0439, 0.0439]

This generates plot using plotly.express

fig = px.line(x=date, y=APY, markers = True, title='Plot created using plotly.express. y is not APY but index',
labels = {
"y": "APY",
"x": "Date"
})
print(fig)
fig.show()

This generates correct plot using matplotlib

fig, ax = plt.subplots(figsize = (16, 5))
ax.scatter(date, APY)
ax.plot(date, APY, linestyle = "-")
ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax = 1.0, decimals = 2))
ax.set_title("Plot created using matplotlib, y is correctly assigned to APY")
plt.xlabel("Date")
plt.ylabel("APY")
plt.show`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions