typestar

figure_builder.ipf in Igor Pro

A publication figure built by code, so the next one matches without anyone remembering how.

#pragma TextEncoding = "UTF-8"
#pragma rtGlobals = 3

Static Function ApplyHouseStyle(String win)
    ModifyGraph/W=$win font="Helvetica", fSize=9, axThick=0.8
    ModifyGraph/W=$win tick=2, mirror=1, standoff=0, lsize=1.2
    ModifyGraph/W=$win margin(left)=44, margin(bottom)=34
End

Function/S TracePanel(WAVE y)
    String win = "PanelTrace"
    DoWindow/K $win
    Display/N=$win/W=(20, 20, 380, 240) y

    ModifyGraph/W=$win rgb=(0, 0, 45000)
    Label/W=$win left, "Signal (V)"
    Label/W=$win bottom, "Time (s)"
    ApplyHouseStyle(win)

    TextBox/W=$win/C/N=tag/A=LT/F=0 "A"
    return win
End

Function/S HistogramPanel(WAVE y)
    String win = "PanelHist"
    DoWindow/K $win

    WaveStats/Q y
    Make/O/N=40/D hist
    Histogram/B={V_min, (V_max - V_min) / 40, 40}/Dest=hist y

    Display/N=$win/W=(20, 260, 380, 480) hist
    ModifyGraph/W=$win mode=5, hbFill=2, rgb=(30000, 30000, 30000)
    Label/W=$win left, "Count"
    Label/W=$win bottom, "Signal (V)"
    ApplyHouseStyle(win)

    TextBox/W=$win/C/N=tag/A=LT/F=0 "B"
    return win
End

Function BuildFigure(WAVE y)
    String trace = TracePanel(y)
    String hist = HistogramPanel(y)

    DoWindow/K Figure1
    NewLayout/N=Figure1
    AppendLayoutObject/F=0/R=(60, 60, 380, 260) graph $trace
    AppendLayoutObject/F=0/R=(60, 280, 380, 480) graph $hist
    ModifyLayout mag=1, units=0

    SavePICT/O/WIN=Figure1/E=-2/B=300 as "figure1.png"
    Print "wrote figure1.png"
    return 0
End

How it works

  1. One function per panel, each returning the window name it made.
  2. The style is applied in one place, so every panel agrees.
  3. The layout assembles them and the export writes the file.

Keywords and builtins used here

The run, in numbers

Lines
55
Characters to type
1330
Tokens
350
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 233 seconds.

Type this snippet

Step 1 of 1 in Encore, step 19 of 19 in Graphs & presentation.

← Previous