Black Lives Matter. Please consider donating to Black Girls Code today.

Categorical ordering in scatter matrix

Hi,

I know it’s possible to create a scattermatrix and define different types for the axis such as “log”,“category”… (go.Splom -> axis_type) but I was wondering whether you can also specify the categoryorder (ascending or descending) of the axis that are defined as type_axis=“category”?

Hi @axelg7, sure, you can update each of the axis individually, like

import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df)
fig.update_layout(xaxis5=dict(autorange="reversed"))
fig.show()

See https://plot.ly/python/axes/ for how to set axes properties (in a subplot, axes are called 'xaxis', 'xaxis2', xaxis3' etc.)

1 Like

Hi @Emmanuelle,
Whenever I execute the code below, the categories corresponding to these axis are not sorted accordingly.

import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df)
fig.update_layout(xaxis5=dict(type='category',categoryorder='category descending'),
                yaxis5=dict(type='category',categoryorder='category ascending'))
fig.show()

Hi @axelg7 I think it’s because in a splom pairs of x and y axis (say xaxis5 and yaxis5) match together so that when you zoom on one then the other updates as well. Therefore you cannot have ascending on one axis and descending on the other, you can check that controlling only one works well. You can “untie” the x and y axis as shown below, but then the y-axis will not update when zooming on the x-axis… It helps to do print(fig) to know which parameter to change.

import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df)
fig.update_layout(
    xaxis5=dict(autorange="reversed")
)
fig.data[0]['dimensions'][4]['axis']['matches']=False
fig.show()