Follow

How can I add a fit curve to a line/scatter plot in Grapher via automation?

This article contains a sample script for creating a line/scatter plot and adding various types of fit curves.

To run this script:

  1. Click here to download the BAS file: fits.BAS
  2. Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.

OR:

  1. Copy the script below.
  2. Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
  3. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  4. Press Ctrl+V to paste it into the Script Manager.
  5. Click the Start/Resume icon () in the Script Manager.
     

*********

Sub Main

 Dim GrapherApp As Object
 Set GrapherApp = CreateObject("Grapher.Application")

 GrapherApp.Visible = True
 Dim Docs As Object
 Set Docs = GrapherApp.Documents

 Dim Plot As Object
 Set Plot = Docs.Add(grfPlotDoc)
 Dim Shapes As Object
 Set Shapes = Plot.Shapes

 Set Graph = Shapes.AddLinePlotGraph(GrapherApp.Path+"\samples\tutorial.dat")

 Dim ScatterPlot As Object
 Set ScatterPlot = Graph.Plots.Item(1)

ScatterPlot.symbolFreq = 1
ScatterPlot.symbol.Index = 38
ScatterPlot.symbol.size = 0.35
ScatterPlot.symbol.color = RGB(255,0,0)
ScatterPlot.symbol.lineColor = grfColorBlue

ScatterPlot.line.style("invisible")

Set FitPolynomial = Graph.Plots(1).AddFit(grfPolynomialFit)
FitPolynomial.Option=4
FitPolynomial.line.foreColor(grfColorGreen)
FitPolynomial.line.width=0.03

Set FitSpline = Graph.Plots(1).AddFit(grfSplineFit)
FitSpline.line.foreColor(grfColorCyan)
FitSpline.line.width=0.03
FitSpline.Option=15


Set FitRunningAvg = Graph.Plots(1).AddFit(grfRunningAvgFit)
FitRunningAvg.line.foreColor(grfColorMagenta)
FitRunningAvg.line.width=0.03
FitRunningAvg.Option=9


Set FitWeightedAvg = Graph.Plots(1).AddFit(grfWeightedAvgFit)
FitWeightedAvg.line.foreColor(grfColorYellow)
FitWeightedAvg.line.width=0.03
FitWeightedAvg.Option=3

End Sub

 

Updated October 11, 2018

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.