Why plotly go see my strings as integer?

Hi,
I realized something with go.bar.
As you see, on x axis there must be “x_variables” but some of them looks like integer and plotly go act like this. Why :confused:

import pandas as pd
import plotly.graph_objects as go
df=pd.DataFrame({"x_variables":['94508', 'a0780', 'b8360', '19c35', '80021', '77593'],
            "y1":[100,100,100,100,100,100],
            "y2":[150,150,150,150,150,150]})

btrace1 = go.Bar(
    x=df["x_variables"],
    y=df["y1"]
)
btrace2 = go.Bar(
    x=df["x_variables"],
    y=df["y1"]
)
bdata = [btrace1, btrace2]
blayout = go.Layout(
    barmode='stack',
    plot_bgcolor='rgba(0,0,0,0)'
)

barp = go.Figure(data=bdata, layout=blayout)
barp

My graph is this. You can check with codes.
aaaaaaaaaaaa

Now i realisez this:

  • If i update x axises like this
df["x_variables"].astype(str)+"_"

there is no problem an I can see my graph like I expected. But this is not the one I want. Because I have a live stream data and I have so much unique id (like in the x axis). And this type of things could not be good for dashboard.

If you have any other option, I wanna hear this.

Hi again,

I didnt solve this issue but I have new question.

I have other 10 variables. And I wanna see as hover info some of them.

My go.bar structure is same as top. And i use this for 1 variable info and it work well.

hovertext=df[“TimeStamp”],

i add this to both of the traces. But when i tried this:

hovertext=[df[“TimeStamp”],df[“anotherVar”],"df[“andAnother”]],

It is not working. I want some advice.

Regarding your initial question, if you upgrade to plotly version 4.14 the axis auto-detection code should do what you expect.

Regarding your other question, you can use px.bar(df, x="var", y="var", hover_data=["var", "var", "var"]) to do this more easily than having to build up your chart from go.Bar() objects.

Hi,

Thanks for answer. But second answer didn’t work well. Because my graph is looks like top.

I have 2 traces, and i use them both with stack bar. I use for this go.Figure(data=data,layout=layout) data=[trace1,trace2] and both my traces are created with go.Bar.

So I’m trying to say, my structure “go” based. If i make one of them with “px” my structure boom.

If you have an advice. I want to hear this.