The newest Grapher release added the ability to define a custom fit curve via automation, as well as change the fit curve equation for a custom fit curve. A sample script to do this can be found 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 Preview\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
0 comments
Please sign in to leave a comment.