SPLOM scatter matrix - changing styles of all axes in one go

Hi,

I can make a scatter matrix for my dataset of 10 columns but some of the column names are quite long. This makes it difficult to read with overlapping titles. For changing individual axis, I use this code:

layout = go.Layout(title = ‘SPLOM title’,
xaxis2 = dict (titlefont = dict(size=5)),
yaxis2 = dict (titlefont = dict(size=5))
)

Is it possible to create a for loop to loop through all the x and y axes? Can the yaxis titles be rotated so they appear horizontally?

Image of the plot

Hi @wujire

Here’s a general approach to looping over the x/y axis objects (see the last three lines below)

from plotly import tools
import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[1, 2, 3],
    y=[4, 5, 6],
    mode='markers+text',
    text=['Text A', 'Text B', 'Text C'],
    textposition='bottom center'
)
trace2 = go.Scatter(
    x=[20, 30, 40],
    y=[50, 60, 70],
    mode='markers+text',
    text=['Text D', 'Text E', 'Text F'],
    textposition='bottom center'
)

fig = tools.make_subplots(rows=1, cols=2, print_grid=False)

fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 1, 2)

for prop in fig.layout:
    if prop.startswith('xaxis') or prop.startswith('yaxis'):
        print(fig.layout[prop])
layout.XAxis({
    'anchor': 'y', 'domain': [0.0, 0.45]
})
layout.YAxis({
    'anchor': 'x', 'domain': [0.0, 1.0]
})
layout.XAxis({
    'anchor': 'y2', 'domain': [0.55, 1.0]
})
layout.YAxis({
    'anchor': 'x2', 'domain': [0.0, 1.0]
})

I don’t think it’s possible to rotate axis titles unfortunately.
Hope that helps
-Jon

Thanks Jon.

What worked for me was to split the column names based on whitespace, insert ‘
’ (br HTML tag) and put everything back together as one string and pass this to the plotly code.