Show Sidebar Hide Sidebar

Make a Line of Best Fit in Plotly 2.0

How to make a line of best fit in Plotly 2.0

Step 1

Getting Started

A line of best fit, also called a trend line or linear regression, is a straight line drawn on a graph that best represents the data on a plot. This line passes through some of the points, all of the points, or none of the points. It can be used to make predictions or to show trends in data. It's a pretty cool feature to add to your plots, so let's get started!

Step 2

Add Your Data

The first step is to head to Plotly’s new online workspace and add your data.

Step 3

Create Your Plot

After your data's been added, go to GRAPH on the left-hand side, then 'Create'. Choose your 'Chart type', and add your traces using the X and Y dropdown (this section is different depending on the chart type).

Like the way we've styled this plot? For more styling tips, see this tutorial!

Step 4

Select Your Fit

When you've finished plotting your data, visit the ANALYSIS section on the left-hand side of your workspace. Click on the blue '+ Analysis' button, then click on the dropdown menu and select 'Fit'.

Analysis section

Select your 'Target Trace' (remember, these are the traces you've set up earlier). You'll then have to select the function you want under 'Function Family'. The dropdown menu has a few to choose from including linear, quadratic, polynomial, and exponential to name a few.

Common fit function

Alternatively, you have the option of adding your own fit function by selecting 'Custom fit function' and entering it in the field. You can also enter your parameters in the 'Constant Estimates' fields.

Custom fit function

Your advanced options include fitting to a specific range and/or displaying your fit over a specific range.

Advanced options

The blue 'More' button on the bottom right will display two output options. You have the choice of setting your output with evenly spaced points and using the slider to enter your points, or your points matching your X data.

More button

The last thing to do is click 'RUN' at the bottom. We've chosen the 'Linear' function, and this is what our plot looks like with the line of best fit.

Run fit

Don't forget to save your graph and show it off to your friends by sharing it. For more information on how to save, share, and export, visit this page!

Still need help?
Contact Us

For guaranteed 24 hour response turnarounds, upgrade to our Premium or Enterprise plans.