admin管理员组

文章数量:1392094

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:

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.

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:

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.

Share Improve this question edited Mar 11 at 19:42 Derek O 19.7k4 gold badges29 silver badges49 bronze badges asked Mar 11 at 17:12 Hugh MungusHugh Mungus 551 silver badge4 bronze badges 5
  • I cannot reproduce the error you're seeing. are you using the latest version of plotly? i am using plotly = v5.23.0 – Derek O Commented Mar 11 at 19:47
  • @DerekO i am using 6.0.0. – Hugh Mungus Commented Mar 11 at 20:00
  • is this what you get when you type %pip show plotly in your jupyter notebook? because I cannot reproduce the behavior you're seeing in a jupyter notebook or locally – Derek O Commented Mar 11 at 20:15
  • @DerekO I think the problem was purely the version type. I changed it to your version and it worked, so maybe its just a bug in the newer version. – Hugh Mungus Commented Mar 11 at 20:16
  • interesting... i am seeing the behavior too now so I believe this is a bug that only shows up when being run in a jupyter notebook – Derek O Commented Mar 11 at 20:18
Add a comment  | 

1 Answer 1

Reset to default 0

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.

本文标签: pythonPlotly displaying numerical values as counts instead of its actual valuesStack Overflow