✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Add polynomial fit line to go.scatter plot

I’d like a add a polynomial curve to a scatter plot that is rendered in callback.

Following is my callback function which returns the scatter plot.

@app.callback(Output('price-graph', 'figure'),
              [
                 Input('select', 'value')
              ]
             )
def update_price(sub):

    if sub:

        fig1 = go.Figure(

            data=[go.Scatter(

                            x=dff['Count'],
                            y=dff['Rent'],
                            mode='markers'

                            )
                  ],

            layout=go.Layout(

                title='',

                xaxis=dict(
                    tickfont=dict(family='Rockwell', color='crimson', size=14)
                ),

                yaxis=dict(

                    showticklabels = True

                ),

            )
        )

        return fig1

Resulting plot:

I am able to add a polyfit line using sklearn.preprocessing.

from sklearn.preprocessing import PolynomialFeatures 
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline


dff = df.groupby(['Rent']).size().reset_index(name='Count')

fig = plt.figure(figsize=(15,8)) 

x = dff['Count']
y = dff['Rent']

model = make_pipeline(PolynomialFeatures(4), LinearRegression())
model.fit(np.array(x).reshape(-1, 1), y)
x_reg = np.arange(90)
y_reg = model.predict(x_reg.reshape(-1, 1))

plt.scatter(x, y)
plt.plot(x_reg, y_reg)
plt.xlim(0,100)
plt.xlabel('Number of rental units leased')
plt.ylim(10,50)
plt.show()

Is there a way to do this in plotly?