Plotly axis titles don't update

Hello!

This is my first app with Anvil and I’m running into the same issue as Plotly Graph Title Issues, except that the proposed fix (self.plot_1.redraw()) doesn’t fix it.

I want to have labels different than x, y, z for the axis labels.

I tried several ways setting them:

  • self.plot_1.layout.xaxis.title = "Lightness"
  • setting the same xaxis=dict(title=...) at layout creation
  • self.plot_1.layout.scene.xaxis.title_text= "Lightness"
  • setting the same scene=dict( xaxis=dict(title_text="Lightness"),... at layout creation

But I don’t think it comes from the way I set it since that kind of setting works in pure Python.

Here’s a link to my app. The relevant code is in the plot3d form, at the end of the file.
https://anvil.works/build#clone:U3TDAZXTKMFFLSC4=FIHD362O5ANZBO5LTKJOOXAZ

Update:
I tried with 2D plots, and it works as expected. So this must have to do with the 3d scatter plot…

Hi @am1,

At layout creation you need to use xaxis=dict(title="Luminosité") not xaxis=dict(title_text ="Luminosité").

You then don’t need to set the titles in your build_color_scatter_plot() function.

Clone with fix:
https://anvil.works/build#clone:3ZI5ZBNRDCESO54U=OK3BC6A3MFSQA4MXSROLXNPI

1 Like

Oh, thank you very much! I thought I had tried all combinations but I missed some clearly! Obviously I don’t need it twice, this was just me trying everything :grinning:

Any idea why this is different than what is used in plotly express? https://github.com/plotly/plotly.py/blob/234ec0daa2429294fe35cbfc6c71f7595896096e/packages/python/plotly/plotly/express/_core.py#L668-L672

I’m asking because I’m afraid that’s not the only place the interface may be different (though it is probably a question of plotly version… well yes, that must be the reason…)