Axis labels on scatter_matrix

I spent few hours seeing if I could replicate sns.pairplot with plotly in an easy way, but is problem after problem.
I gave up on try to do the histogram on the diagonal because I saw that is a work in progress (https://github.com/plotly/plotly_express/issues/42).

In seaborn I used:

sns.pairplot(data)

and I got in 16s:

In plotly after deciding not to use ff.create_scatterplotmatrix() because is deprecated and also need to play with the width and height, I tried with plotly express and got in 66ms:

px.scatter_matrix(data[numeric_cols])

Then I had to start playing with the size and the marker size because the points were too big to see the distribution, and I got this in 72ms:

fig = px.scatter_matrix(data[numeric_cols], height=800, width=800)
fig.update_traces(marker=dict(size=1, line=dict(width=1, color="DarkSlateGrey")))
fig.update_traces(diagonal_visible=False)
fig.show()

But still the axis labels are impossible to handle, I tried with fig.update_xaxes(tickangle=45) but it only works for the labels inside, and only the first graph. And even if works maybe it will not work for all axis.

So, my question is if there are some automatic way to fix the size without needing to start trying different width/height, axis labels not overlapping… or what is the best hotfix?

EDIT: Btw if someone wants to replicate the dataset is a modified version of https://www.kaggle.com/unsdsn/world-happiness

1 Like

Your best bet would be to reduce the font size, with e.g. layout.font.size

1 Like

And is possible to rotate the axis labels? I mean, if I can rotate them 45 or 90 degrees I think it could work in combination with the font size.

Yes, you can alter any property on the axes, but unfortunately you can’t use update_xaxes() in this case, as the axes are implicitly created in the Javascript layer, so you’ll need to enumerate the axes you’re targeting for update:

import plotly.express as px

fig = px.scatter_matrix(px.data.tips())
fig.update_layout({"xaxis"+str(i+1): dict(tickangle = -45) for i in range(7)})
fig.show()
1 Like

I just tried it, but this turns the numbers of each graph. I meant more the texts overlapping (‘Happiness Rank’, ‘Happiness Score’…) and the rest that we can read clearly in the last photo because they are overlapped.

I thought that with a 45 degrees angle on those texts, they would be mostly readable.

Gotcha. We don’t have an attribute for that, no. Really your only option is to reduce the font size relative to the figure size, either by reducing the former or increasing the latter.

Is this still the case that the labels on a matrix scatter plot cannot be rotated? How about removing just the Y axis labels? Chaning the font so it fits is not really an option or at least makes reading the labels hard and we can always use mouse over to find which two variables are plotted, so just removing them would be OK…

fig.update_yaxes(visible=False)

Does not seem to do the trick…

I am facing the same issue wth overlapping labels on axes with px.scatter_matrix and nothing is working. Does any solution or workaround available even now for this apart from font size?