Add relative axis scales in Grapher via automation

Grapher allows each axis to be scaled separately using axis minimum, maximum, and length values. There is not a scale setting to control how many units occur over a given page length. However we have created a script that will do this: set Y scale to match X scale.bas

To run this script:

  1. Open the file in Grapher containing the plot you want to change the scaling of.
  2. Copy the script below.
  3. Turn on the Script Manager by clicking View | Display | Script Manager.
  4. Press Ctrl+A to select all of the existing lines in the Script Manager and then press DELETE.
  5. Press Ctrl+V to paste it into the Script Manager.
  6. Click the Start/Resume icon in the Script Manager.

'This script determines the X Axis scale
'and sets the Y Axis length so that the scales match

Sub Main

'Initialize Grapher
Dim Grapher As Object
Set Grapher = CreateObject("Grapher.Application")
Grapher.Visible = True

'Set the open Grapher document to the Plot variable name
Set Plot = Grapher.Documents.Active

'Define variables for axes
Set XAxis1 = Plot.Shapes.Item(1).Axes.Item(1)
Set YAxis1 = Plot.Shapes.Item(1).Axes.Item(2)

'Determine the X Scale
scale = (XAxis1.Max - XAxis1.Min)/XAxis1.length

'Get the absolute value of scale
If scale < 0 Then scale = scale * -1

'Set the Y Axis length so that it uses the same scale
YAxis1.length = (YAxis1.Max-YAxis1.Min)/scale

End Sub

 

Updated March 13, 2020

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.