Add a fit curve to a line/scatter plot in Grapher via automation
Each of Grapher's support fit types can be added via automation. See the AddFit and grfFitTypes help pages for additional details about the available options. The sample script below creates a few different fit curves and adjusts the properties of each.
To run this script:
- Click here to download the BAS file: fits.BAS.
- Click Automation | Scripts | Run, select the BAS file from your downloads directory, and click Open.
OR:
- Copy the script below.
- Open Grapher and turn on the Script Manager by clicking View | Display | Script Manager.
- Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
- Press Ctrl+V to paste it into the Script Manager.
- Click the green arrow Start/Resume icon in the Script Manager.
Sub Main Dim GrapherApp, Docs, Plot, ScatterPlot As Object Set GrapherApp = CreateObject("Grapher.Application") GrapherApp.Visible = True Set Docs = GrapherApp.Documents Set Plot = Docs.Add(grfPlotDoc)
'Creates a line plot and assigns the graph and plot to variable names Set Graph = Plot.Shapes.AddLinePlotGraph(GrapherApp.Path+"\samples\tutorial.dat") Set ScatterPlot = Graph.Plots.Item(1)
'Adjusts the symbol and line properties for the plot ScatterPlot.symbolFreq = 1 ScatterPlot.symbol.Index = 30 ScatterPlot.symbol.size = 0.25 ScatterPlot.symbol.color = RGB(0,0,255) ScatterPlot.symbol.lineColor = grfColorBlue ScatterPlot.line.style("invisible")
'Adds a polynomial fit curve to the plot Set FitPolynomial = Graph.Plots(1).AddFit(grfPolynomialFit) FitPolynomial.Option=4 FitPolynomial.line.foreColor(grfColorGrassGreen) FitPolynomial.line.width=0.03
'Adds a spline fit curve to the plot Set FitSpline = Graph.Plots(1).AddFit(grfSplineFit) FitSpline.line.foreColor(grfColorNavyBlue) FitSpline.line.width=0.03 FitSpline.Option=15
'Adds a running average fit curve to the plot Set FitRunningAvg = Graph.Plots(1).AddFit(grfRunningAvgFit) FitRunningAvg.line.foreColor(grfColorAutumnOrange) FitRunningAvg.line.width=0.03 FitRunningAvg.Option=9
'Adds a weighted average fit curve to the plot Set FitWeightedAvg = Graph.Plots(1).AddFit(grfWeightedAvgFit) FitWeightedAvg.line.foreColor(grfColorRubyRed) FitWeightedAvg.line.width=0.03 FitWeightedAvg.Option=3 End Sub
Updated August 13, 2019
Comments
0 comments
Please sign in to leave a comment.