I have been using Plotly lately for its great interactive features. I am wondering if I can generate a correlation scatter plot with best line fit, as I used to do in seaborn, using regplot() method (just like the following figure)?
and extract from rg the regression line data and the Path(s) bounding the confidence interval band, to plot them via Plotly:
X=rg.get_lines()[0].get_xdata()# x-coordinate of points along the regression line
Y=rg.get_lines()[0].get_ydata()# y-coordinate
P=rg.get_children()[1].get_paths()#The list of Path(s) bounding the shape of 95% confidence interval-transparent
Define two traces of type scatter: one for your data points and the second for the regression line, defined by X and Y.
To get the transparent confidence interval band along the regression line, extract the path describing the boundary of that band as follows:
p_codes={1:'M', 2: 'L', 79: 'Z'}#dict to get the Plotly codes for commands to define the svg path
path=''
for s in P[0].iter_segments():
c=p_codes[s[1]]
xx, yy=s[0]
path+=c+str('{:.5f}'.format(xx))+' '+str('{:.5f}'.format(yy))
shapes=[dict(type='path',
path=path,
line=dict(width=0.1,color='rgba(68, 122, 219, 0.25)' ),
fillcolor='rgba(68, 122, 219, 0.25)')]
layout['shapes']=shapes