- axis ticks can be rotated. I cannot find any way to rotate labels
- as a workaround, replace labels and add a key
import plotly.express as px
df = px.data.iris()
fig = px.scatter_matrix(df)
# rotate text in yaxes, if text
fig.update_layout(
{
f"yaxis{n+1 if n>0 else ''}": {"tickangle": 45}
for n in range(len(fig.data[0].dimensions))
if isinstance(fig.data[0].dimensions[n].values[0], str)
}
)
# get labels of dimensions in splom
labels = [d.label for d in fig.data[0].dimensions]
# replace labels in splom with identifier
fig.update_traces(
dimensions=[d.update(label=chr(ord("a")+n)) for n, d in enumerate(fig.data[0].dimensions)]
)
# add a key for labels
for n, l in enumerate(labels):
fig.add_annotation(
x=(n) / (len(labels)-1),
y=1.2,
xref="paper",
yref="paper",
text=f"{chr(ord('a')+n)}. {l}",
align="center",
showarrow=False,
)
fig
