The capability to automate the creation of a custom fit curve and modify the fit curve equation is available in Grapher versions 20.1.151 and above. A script exemplifying this functionality is provided below.
To run this script:
- 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.
- Update the lines in the User-defined parameters section.
- Click the green arrow Start/Resume icon in the Script Manager.
Sub Main 'Initialize Grapher Dim Grapher As Object Set Grapher = CreateObject("Grapher.Application") Grapher.Visible = True '======================================== 'User-defined parameters '======================================== file$ = "C:\Program Files\Golden Software\Grapher\Samples\Line scatter plot.gpj" 'Fit equations and name fit1 = "Y = m*x+b" fitname = "Custom Fit 1" fit2 = "Y = m*x^2+b" 'Parameters Dim Array1(1) As String Array1(0) = "m" Array1(1) = "b" 'Initial Values Dim Array2(1) As Double Array2(0) = 0 Array2(1) = 0 'Minimums Dim Array3(1) As Double Array3(0) = -1.79769e+308 Array3(1) = -1.79769e+308 'Maximums Dim Array4(1) As Double Array4(0) = 1.79769e+308 Array4(1) = 1.79769e+308 '======================================== 'Open an existing file containing a line plot Set linescatterplotgpj = Grapher.Documents.Open(file$) 'Define object pointer Set Graph3 = linescatterplotgpj.Shapes.Item(1) Set LineScatterPlot = Graph3.Plots.Item(1) 'Create the custom fit Grapher.AddCustomFitDefinition(fitname, fit1, Array1, Array2, Array3, Array4) 'Add the custom fit to the plot LineScatterPlot.AddFit(grfCustomFit, fitname) Set Fit = Graph3.Plots.Item(5) 'Change the custom fit equation Fit.SetCustomEquation(fit2) End Sub
Updated March 10, 2020
Comments
Please sign in to leave a comment.