Create a graph with multiple plots where the Y column increments by one for each plot in Grapher

This article contains a sample Grapher script which shows how to create a graph with multiple line/scatter plots from adjacent Y columns. The Y column automatically increments to the next column in order to create the next plot. So, for example, if you had a data file with 4 columns, the first line/scatter plot would use column 1 for x and column 2 for y, the second plot would use column 1 for x and column 3 for y, and the third plot would use column 1 for x and column 4 for y.

 

To run this script:

  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 green arrow Start/Resume icon in the Script Manager.

 


Sub Main

'Initialize Grapher
Dim GrapherApp, Docs, Plot, Graph1 As Object
Set GrapherApp = CreateObject("Grapher.Application")
GrapherApp.Visible = True
Set Docs = GrapherApp.Documents
Set Plot = Docs.Add(grfPlotDoc)

'=========================
'User-defined variables
'=========================
'File path and name
File=GrapherApp.Path + "\Samples\Sample3.dat"

'Total number of plots to create
numplots = 3
'=========================

'Create a line plot
Set Graph1 = Plot.Shapes.AddLinePlotGraph(File,1,2)

'Define the first y column to add a plot using
plotcol = 3

'Set the last y column to add a plot using
lastplotcol = plotcol + numplots - 1

'Loop through all y columns to add a plot using
While plotcol < lastplotcol
    'Adds a line plot using column A as X and the next column as Y
    Graph1.AddLinePlot(File,1,plotcol,,,)
    plotcol =plotcol +1
Wend

End Sub

 

Updated March 9, 2020

Was this article helpful?
4 out of 7 found this helpful

Comments

0 comments

Please sign in to leave a comment.