XDL Graphics Quick Reference
Available Demo Scripts
1. plot_demo.xdl - Simple 2D Plot
Basic sine wave demonstration.
xdl-gui examples/plot_demo.xdl
2. plot_working_demo.xdl - Comprehensive 2D Tests
Tests all 2D plotting features with 5 different plots.
xdl-gui examples/plot_working_demo.xdl
3. plot3d_demo.xdl - 3D Plotting Tests
Tests 3D data structures with SURFACE, CONTOUR, SHADE_SURF, and PLOT3D.
xdl examples/plot3d_demo.xdl
Quick Examples
2D Line Plot
x = FINDGEN(50) / 5.0
y = SIN(x)
PLOT, y, x
3D Surface Plot
z = [[1, 2, 3, 2, 1], [2, 4, 6, 4, 2], [3, 6, 9, 6, 3]]
SURFACE, z
Array Math
x = FINDGEN(10)
y = COS(x * 2.0) ; Array multiplication and COS
z = EXP(-x) ; Array negation and EXP
w = x + SIN(x) ; Array addition
Supported Procedures
✅ Fully Working
PLOT- 2D line plots with GUI/PNG outputSURFACE- Parses 2D arrays for 3D surfacesCONTOUR- Parses 2D arrays for contoursSHADE_SURF- Parses 2D arrays for shaded surfacesPLOT3D- Parses 3 1D arrays for 3D lines
⚠️ Registered (Stubs)
See GRAPHICS_DEMOS_STATUS.md for complete list of 40+ registered procedures.
Supported Math Functions (with Array Support)
SIN,COS,TAN- Trigonometric functionsASIN,ACOS,ATAN- Inverse trig functionsEXP- ExponentialSQRT- Square rootABS- Absolute valueFINDGEN- Generate float arrays
Array Operations
Arithmetic
a = [1, 2, 3]
b = [4, 5, 6]
c = a + b ; [5, 7, 9]
d = a * 2.0 ; [2, 4, 6]
e = a / 2.0 ; [0.5, 1.0, 1.5]
Unary
x = [1, 2, 3]
neg_x = -x ; [-1, -2, -3]
Element-wise Functions
angles = FINDGEN(10) * 0.1
sines = SIN(angles) ; Sin of each element
exps = EXP(-angles) ; Exp of each negative element
Nested Arrays for 2D Data
; 3x3 matrix
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
; Access rows
row1 = matrix[0] ; [1, 2, 3]
; Access elements
elem = matrix[1, 1] ; 5
; Use in 3D plots
SURFACE, matrix
Common Patterns
Plotting Waves
t = FINDGEN(100) / 10.0
y = SIN(t)
PLOT, y, t
Exponential Decay
t = FINDGEN(50) / 5.0
y = EXP(-t)
PLOT, y, t
Combined Functions
x = FINDGEN(80) / 8.0
y = SIN(x) + COS(x * 2.0)
PLOT, y, x
3D Parametric Curves
t = FINDGEN(50) / 5.0
x = COS(t)
y = SIN(t)
z = t / 2.0
PLOT3D, x, y, z
Tips
- GUI vs CLI: Use
xdl-guifor interactive plots,xdlfor PNG output - Array Size: Keep demo arrays small (< 100 elements) for quick testing
- Nested Arrays: All rows must have same length for 2D data
- Math Functions: All support both scalars and arrays
- Negation: Use parentheses for clarity:
y = EXP(-(x))ory = EXP(-x)
Troubleshooting
“Unknown procedure: PLOT”
Make sure you’re running the correct binary:
# GUI mode
xdl-gui script.xdl
# CLI mode
xdl script.xdl
“Type mismatch” errors
Check that math functions are using correct types. All should work with arrays now.
“Expected a 2D nested array”
For SURFACE/CONTOUR/SHADE_SURF, use nested array literals:
z = [[1,2,3], [4,5,6], [7,8,9]] ; Correct
z = FLTARR(3, 3) ; Not yet implemented
See Also
GRAPHICS_DEMOS_STATUS.md- Detailed status of all proceduresGRAPHICS_FIXES_SUMMARY.md- Recent fixes and changesQUICKSTART_GRAPHICS.md- Complete graphics guideGRAPHICS_IMPLEMENTATION.md- Technical implementation details