pythonjupyter-notebookplotlybar-chart

Plotly displaying numerical values as counts instead of its actual values?


I am trying to plot my pandas df data onto a plotly bar chart, but for some reason, instead of putting the numerical values on the chart, its just putting the order onto it.

For example, I am trying to also follow along with the docs, but it also fails on the docs' example.

The code:

import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()

shows a chart of this:

enter image description here

the bar values are the indexes of the array, rather than their actual values.

I presume it might be with an issue with my install, but I am not entirely sure. Any help would be appreciated, as I haven't been able to find other solutions elsewhere.


Solution

  • I tested this out, and this appears to be a bug that only appears when using plotly v6.0.0 in a jupyter notebook. For now, the issue can be worked around by downgrading the version inside the notebook: %pip install plotly==5.23.0

    You'll notice that if you try to plot fig = px.bar(x=["a", "b", "c"], y=["1", "3", "2"]) you get the same, undesired behavior so it's possible that when plotly is run from a jupyter notebook and px.bar is called using lists passed to x and y, the y values are being converted to strings under the hood.