Splom layout updating

I have some data which I am plotting using px.scatter_matrix giving me splom traces. However I think I am misunderstanding how I can update (or even if I can update) what I would think are “layout” attributes in a splom plot. Here is a MRP:

import plotly.express as px
df = px.data.gapminder().query("year==2007")
fig = px.scatter_matrix(df, dimensions=["pop", "lifeExp", "gdpPercap"],
                        color="continent", title="Gapminder 2007")
fig.show()
# Lets change the y label in the top left plot
fig = fig.update_yaxes(title_text="Population", row=1, col=1)
fig.show() # Nothing happens!

I read through the fundamentals of the figure carefully and when I print the figure I can see labels assigned to each trace, but I cannot figure out how these can be updated and why they are not a part of the layout. Would someone be able to help me understand what I am missing regarding the functinoality of splom plots and where I can go for a reference to understand the functionality going forward? Thank you so much for your help!

Hi @naveace welcome to the community and thanks for the MRP.

When I do not know how to alter specific items of a chart, I usually convert the figure into a dictionary with fig.to_dict() and inspect it. In general, plotly uses a nested structure like a dictionary or json.

So doing that with the px.scatter_matrix shows, that the label of the pop hides here:

fig.data[0]['dimensions'][0]['label']

You can change this to whatever you like via
fig.data[0]['dimensions'][0]['label']='Population'

Full code:

import plotly.express as px
df = px.data.gapminder().query("year==2007")
fig = px.scatter_matrix(df, dimensions=["pop", "lifeExp", "gdpPercap"],
                        color="continent", title="Gapminder 2007")

fig.data[0]['dimensions'][0]['label']='Population'
fig.show()

creates:
newplot (11)

There might be other ways to do this and maybe even built in functions, but my experience with these type of “special figures” is somewhat limited.

Thanks so much! Very helpful :slight_smile: