Vector Graphics¶
XY mode vector graphics generation
Vector graphics generation for oscilloscope XY mode display.
This module enables drawing shapes, text, and animations on the oscilloscope screen by generating synchronized waveforms for X and Y channels. Requires the 'fun' extras: pip install "Siglent-Oscilloscope[fun]"
Examples:
>>> from scpi_control import Oscilloscope
>>> from scpi_control.vector_graphics import VectorDisplay, Shape
>>>
>>> scope = Oscilloscope('192.168.1.100')
>>> scope.connect()
>>>
>>> # Create vector display using CH1 (X) and CH2 (Y)
>>> display = VectorDisplay(scope, ch_x=1, ch_y=2)
>>> display.enable_xy_mode()
>>>
>>> # Draw a circle
>>> circle = Shape.circle(radius=1.0, points=1000)
>>> display.draw(circle)
>>>
>>> # Draw text
>>> text = Shape.text("HELLO", font_size=0.5)
>>> display.draw(text)
>>>
>>> # Animate rotation
>>> for angle in range(0, 360, 5):
... rotated = text.rotate(angle)
... display.draw(rotated)
VectorPath
dataclass
¶
Represents a vector graphics path as X and Y coordinate arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
X coordinates (normalized to -1.0 to 1.0) |
y |
ndarray
|
Y coordinates (normalized to -1.0 to 1.0) |
connected |
bool
|
Whether to connect end to start (closed path) |
scale
¶
translate
¶
rotate
¶
Rotate the path around an origin point.
Source code in scpi_control/vector_graphics.py
flip_x
¶
flip_y
¶
combine
¶
Combine two paths (concatenate points).
Source code in scpi_control/vector_graphics.py
Shape
¶
Factory class for creating common vector graphics shapes.
circle
staticmethod
¶
Generate a circle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Circle radius (0.0 to 1.0 normalized) |
1.0
|
points
|
int
|
Number of points for smoothness |
1000
|
center
|
Tuple[float, float]
|
Center coordinates (x, y) |
(0, 0)
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the circle |
Source code in scpi_control/vector_graphics.py
line
staticmethod
¶
Generate a line segment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
Tuple[float, float]
|
Starting point (x, y) |
required |
end
|
Tuple[float, float]
|
Ending point (x, y) |
required |
points
|
int
|
Number of points along the line |
100
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the line |
Source code in scpi_control/vector_graphics.py
rectangle
staticmethod
¶
rectangle(width: float, height: float, center: Tuple[float, float] = (0, 0), points_per_side: int = 100) -> VectorPath
Generate a rectangle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Rectangle width |
required |
height
|
float
|
Rectangle height |
required |
center
|
Tuple[float, float]
|
Center coordinates (x, y) |
(0, 0)
|
points_per_side
|
int
|
Points per side for smoothness |
100
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the rectangle |
Source code in scpi_control/vector_graphics.py
polygon
staticmethod
¶
Generate a polygon from vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
List[Tuple[float, float]]
|
List of (x, y) vertex coordinates |
required |
points_per_side
|
int
|
Points per side for smoothness |
100
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the polygon |
Source code in scpi_control/vector_graphics.py
star
staticmethod
¶
star(num_points: int = 5, outer_radius: float = 1.0, inner_radius: float = 0.4, center: Tuple[float, float] = (0, 0), points_per_line: int = 50) -> VectorPath
Generate a star shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_points
|
int
|
Number of star points |
5
|
outer_radius
|
float
|
Radius to outer points |
1.0
|
inner_radius
|
float
|
Radius to inner points |
0.4
|
center
|
Tuple[float, float]
|
Center coordinates (x, y) |
(0, 0)
|
points_per_line
|
int
|
Points per line segment |
50
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the star |
Source code in scpi_control/vector_graphics.py
text
staticmethod
¶
text(text: str, font_size: float = 0.5, position: Tuple[float, float] = (0, 0), samples_per_unit: int = 200) -> VectorPath
Generate text as vector paths.
Note: Requires PIL (Pillow) to be installed. This creates simple text outlines. For better results, use SVG fonts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text string to render |
required |
font_size
|
float
|
Font size (normalized) |
0.5
|
position
|
Tuple[float, float]
|
Position (x, y) |
(0, 0)
|
samples_per_unit
|
int
|
Sampling density for contours |
200
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the text |
Source code in scpi_control/vector_graphics.py
lissajous
staticmethod
¶
Generate Lissajous curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
int
|
Frequency ratio for X |
3
|
b
|
int
|
Frequency ratio for Y |
2
|
delta
|
float
|
Phase shift |
pi / 2
|
points
|
int
|
Number of points |
2000
|
Returns:
| Type | Description |
|---|---|
VectorPath
|
VectorPath representing the Lissajous curve |
Source code in scpi_control/vector_graphics.py
VectorDisplay
¶
Manages oscilloscope XY mode display for vector graphics.
This class configures the oscilloscope for XY mode and provides methods to draw vector graphics by generating synchronized waveforms.
Note: This requires an external AWG/DAC to feed signals into the scope channels, or the scope's built-in AWG if available. The VectorDisplay class generates the waveform data that should be loaded into the AWG.
Examples:
>>> display = VectorDisplay(scope, ch_x=1, ch_y=2)
>>> display.enable_xy_mode()
>>> circle = Shape.circle(radius=0.8)
>>> display.draw(circle)
Initialize vector display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
oscilloscope
|
Oscilloscope instance |
required | |
ch_x
|
int
|
Channel number for X axis (default: 1) |
1
|
ch_y
|
int
|
Channel number for Y axis (default: 2) |
2
|
Source code in scpi_control/vector_graphics.py
enable_xy_mode
¶
Enable XY display mode on the oscilloscope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voltage_scale
|
float
|
Voltage scale per division for both channels |
1.0
|
Source code in scpi_control/vector_graphics.py
disable_xy_mode
¶
Disable XY mode and return to normal time-domain display.
Source code in scpi_control/vector_graphics.py
draw
¶
Draw a vector path on the oscilloscope.
Note: This method generates waveform data that should be loaded into an external AWG or the scope's built-in AWG. It does not directly control the scope's display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
VectorPath
|
VectorPath to draw |
required |
sample_rate
|
float
|
Desired sample rate (Hz) for the AWG |
1000000.0
|
duration
|
float
|
Duration to display (seconds) |
0.1
|
Returns:
| Type | Description |
|---|---|
|
Tuple of (x_waveform, y_waveform) as numpy arrays ready for AWG upload |
Source code in scpi_control/vector_graphics.py
save_waveforms
¶
save_waveforms(path: VectorPath, filename_prefix: str, sample_rate: float = 1000000.0, duration: float = 0.1, format: str = 'csv')
Generate and save waveforms to files for AWG upload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
VectorPath
|
VectorPath to draw |
required |
filename_prefix
|
str
|
Prefix for output files (e.g., 'circle') |
required |
sample_rate
|
float
|
Sample rate for AWG (Hz) |
1000000.0
|
duration
|
float
|
Duration (seconds) |
0.1
|
format
|
str
|
Output format ('csv', 'npy', or 'bin') |
'csv'
|
Source code in scpi_control/vector_graphics.py
See Also¶
- Oscilloscope - Main oscilloscope control class for SCPI communication
- Waveform - Waveform acquisition and data handling