[Python] Plotly yaxis shift does not work properly

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    Its my first question here, i hope it is detailed enough (images are linked). I am using nicegui (2.14.1) and plotly (6.0.1) with python 3.13.0.

    Usecase: There is a plot with 6 y axes that is update every seconds with real time data and the possibility to set the visibility of all axes. Also, there are two modes, a live mode where, like i said, the plot is update every seconnd and a pause mode where the plot is not updated untill the live mode is on again. When all axes are visible and the user wants to see one axes, he clicks on a button that represents that specific axis and only that axis is visible. If he clicks another one, than two axis are visible. If another one, then three. When he "unselect" (clicks the buttons again) the visibility of these are set again to false. If all are False or True, then all axes are visible. live mode, all axes visible live mode, 4 axes visible

    I am using the update_layout and updatetraces like below:

    self.figure.update_layout(yaxis2 = dict( shift = shift, visible = True))
    self.figure.update_traces(selector=dict(name='dt_2'), patch=dict(visible=True))

    self.plot.figure = self.plotly_handler.figure
    self.plot.update()


    The shift is calculated so there is no empty space between axes that are visible and axes that are not visible. That works completely fine in live mode! I asume it works because the plot gets new data and is forced to do a relayout. But when i am in pause mode following happen:

    1. all axes are visible (works fine)
    2. clicks on four buttons (wortks fine, all shifts are correct)
    3. clicks two of these buttons again -> empty space between the two that are still possible pause mode, just 2 axxes visible
    4. clicks last two buttons again -> all are visible and shifts are correct

    The big problem comes now: if i click a button again, the shifts are no longer correct! It looks like the axes value and the tick are on their right place but the vertical line is shifted completely wrong! pause mode, shifts are all over the place What should i do?

    i used deepcopy i hope that plotly recognize that there is a "completly new plot" but its just the current one but with different address. i als seareched for relayout and uirevision, but its javascript and not the ideale solution for me.

    Continue reading...

Compartilhe esta Página