[Python] How do I remove the numbers displayed on hovering over markers in Plotly Express?...

Discussão em 'Python' iniciado por Stack, Julho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to plot a random walk using Plotly Express only. I want to remove the numbers being displayed when I hover over the markers on the plot.

    I've tried hoverinfo="skip" and hoverinfo="none" inside ig.update_traces() to no avail.

    My code:

    import plotly.express as px
    from random_walk import RandomWalk

    rw = RandomWalk()
    rw.fill_walk()

    title = "Random Walk"
    fig = px.scatter(x=rw.x_values, y=rw.y_values, title=title, labels={"x" : '', "y" : ''})
    fig.update_traces(marker={"size" : 2, "color" : list(range(rw.points)), "colorscale" : "Bluered", "showscale" : False}, **hoverinfo="skip"**)
    fig.update_xaxes(showticklabels=False)
    fig.update_yaxes(showticklabels=False)

    fig.add_scattergl(x=list([0]), y=list([0]), marker=dict(size=20, color="green"), name="start")
    fig.add_scattergl(x=list([rw.x_values[-1]]), y=list([rw.y_values[-1]]), marker=dict(size=20, color="purple"), name="end")
    fig.show()


    Numbers are displayed upon hovering:

    [​IMG]

    Continue reading...

Compartilhe esta Página