How to draw a regression lines on create_scatterplotmatrix?

Hello

i want to draw regression line on create_scatterplotmatrix or px.scatter_matrix like lmplot.
but Plotly does not support such functionality.(not a scatter plot).
So i edit create_scatterplotmatrix and other function little, to take trendline argument, anyway i success draw regression line on create_scatterplotmatix.
but i found legend is messy

  1. per every line, legend is created.How can I consolidate the legends for each line so that they are handled collectively?
  2. If I have the opportunity, I would like to contribute this to the Plotly open-source project. Are there any additional requirements or guidelines I should be aware of??
  3. It seems that create_scatterplotmatrix inherently has many limitations. Would it be better to add linear regression lines using px.scatter_matrix?

The flexible approach may be to use plotly.graph_objects. The outline approach is:

fig = make_subplots(rows=..., cols=..., subplot_titles = ...)
for ...:    # Loop over subplots and sets of points / lines to be added
    fig.add_trace(go.Scatter(x=..., y=...,  name=..., 
                           legendgroup=..., showlegend=...,
                           mode=..., 
                           line={'color':...},)
                  row=row, col=col)

β€˜showlegend’ and β€˜legendgroup’ control which legend items appear and how they are linked together

2 Likes