Printing and Display¶
Figure export, axis labelling with SI prefixes, colour maps, and figure layout helpers.
Figure export and layout¶
v_fig2pdf
¶
V_FIG2PDF - Save a figure to PDF/EPS/PS format.
v_fig2pdf
¶
Save a matplotlib figure to PDF, EPS or PS format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Figure or str
|
Figure handle, or file path string (for convenience). If None, uses the current figure. |
None
|
s
|
str
|
File name. Can include ' |
None
|
p
|
array_like
|
If provided, call v_figbolden(p) before saving. |
None
|
f
|
str
|
Output format string: 'p' for PDF (default), 'e' for EPS, 's' for PS. |
'p'
|
fig
|
Figure
|
Alternative figure handle (overrides h if both provided). |
None
|
Notes
Unlike the MATLAB version, this does not require MikTeX/pdfcrop. Uses matplotlib's built-in savefig with tight_layout.
Source code in pyvoicebox/v_fig2pdf.py
v_fig2emf
¶
V_FIG2EMF - Save a figure in various image formats.
v_fig2emf
¶
Save a matplotlib figure in various image formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
Figure or str
|
Figure handle, or file path string. If None, uses the current figure. |
None
|
s
|
str
|
File name. Can include ' |
None
|
p
|
array_like
|
If provided, call v_figbolden(p) before saving. |
None
|
f
|
str
|
Output format. One of: 'svg', 'pdf', 'eps', 'ps', 'png', 'jpeg', 'tiff', 'meta' (saved as SVG). Default is 'svg'. |
'svg'
|
fig
|
Figure
|
Alternative figure handle. |
None
|
Notes
The MATLAB 'meta' (EMF) format is not natively supported by matplotlib. We use SVG as a substitute which is also a vector format.
Source code in pyvoicebox/v_fig2emf.py
v_figbolden
¶
V_FIGBOLDEN - Embolden, resize and recolour the current figure.
v_figbolden
¶
Embolden, resize and recolour a matplotlib figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
array_like
|
Figure size as [width, height] in pixels, or [xmin, ymin, width, height]. If a single negative number, fix aspect ratio to -width/height preserving area. If a single positive number, use 4:3 aspect ratio. |
None
|
pv
|
dict
|
Dictionary of property-value pairs to apply. Default is: |
None
|
m
|
str
|
Mode string: 'l' - list changes made (print to stdout) 'd' - use default pv settings 'c' - change default colours for better contrast 'x' - suppress all changes |
''
|
fig
|
Figure
|
Figure handle. Default is plt.gcf(). |
None
|
Source code in pyvoicebox/v_figbolden.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
v_axisenlarge
¶
V_AXISENLARGE - Enlarge the axes of a figure.
v_axisenlarge
¶
Enlarge the axes of a matplotlib plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
float or array_like
|
Enlarge axis by a factor f relative to current size. If negative, shrink to fit content before enlarging by abs(f). Can be scalar, [fx, fy], [fx, fy, fz], [fleft, fright, fbottom, ftop], or [fleft, fright, fbottom, ftop, fdown, fup]. Default is -1.02. |
None
|
ax
|
Axes
|
Axes handle. Default is current axes (plt.gca()). |
None
|
Source code in pyvoicebox/v_axisenlarge.py
v_tilefigs
¶
V_TILEFIGS - Tile current figure windows.
v_tilefigs
¶
Tile current matplotlib figure windows on screen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pos
|
array_like
|
Virtual screen region [xmin, ymin, width, height]. Values >= 1 are pixels, values in (0,1) are normalized. Default uses the full screen minus taskbar. |
None
|
Notes
This function works with matplotlib backends that support window management (e.g., TkAgg, Qt5Agg). It will have no effect with non-interactive backends (e.g., Agg).
Source code in pyvoicebox/v_tilefigs.py
Axes and colour¶
v_colormap
¶
V_COLORMAP - Set and create custom color maps.
Provides custom colormaps and luminance linearization for matplotlib.
v_colormap
¶
Create or modify a color map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_input
|
str or ndarray
|
Either an (r, 3) RGB array or a string naming a colormap. Custom maps: 'v_thermliny', 'v_bipliny', 'v_bipveey', 'v_circrby'. Standard matplotlib maps can also be specified by name. If None, returns the default 'viridis' colormap. |
None
|
m
|
str
|
Mode string: 'y' - force luminance^p to be linear or V-shaped 'l' - force lightness^p to be linear or V-shaped 'Y' - like 'y' but with default p=⅔ 'L' - like 'l' but with default p=2 'f' - flip the map 'b'/'B' - force minimum luminance >= 0.05/0.10 'w'/'W' - force maximum luminance <= 0.95/0.90 'g' - plot information about the colormap 'k' - keep the current colormap |
''
|
n
|
int or array_like
|
Number of entries in the colormap, or number per segment. |
None
|
p
|
float
|
Power law exponent for luminance/lightness linearization. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
rgb |
ndarray
|
(N, 3) RGB colormap array with values in [0, 1]. |
y |
ndarray
|
Column vector of luminance values. |
l |
ndarray
|
Column vector of lightness values. |
Source code in pyvoicebox/v_colormap.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
v_colormap_to_mpl
¶
Create a matplotlib LinearSegmentedColormap from a v_colormap specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_or_rgb
|
str or ndarray
|
Colormap name or RGB array (same as v_colormap). |
required |
m
|
str
|
Mode string (same as v_colormap). |
''
|
n
|
int or array_like
|
Number of entries (same as v_colormap). |
None
|
p
|
float
|
Power law (same as v_colormap). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
cmap |
ListedColormap
|
A matplotlib colormap object. |
Source code in pyvoicebox/v_colormap.py
v_lambda2rgb
¶
V_LAMBDA2RGB - Convert wavelength to XYZ or RGB colour space.
v_lambda2rgb
¶
Convert wavelength to XYZ or RGB colour space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
l
|
array_like
|
Wavelength(s) in nanometres. |
required |
m
|
str
|
Mode: 'r' - output is [R G B] using 1931 observer with negatives clipped (default) 's' - output is [R G B] using 1931 observer with signed values 'x' - output is [X Y Z] using 1931 observer Use uppercase 'R', 'S', 'X' for 1964 observer. |
'r'
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Tristimulus values, shape (n, 3). |
Source code in pyvoicebox/v_lambda2rgb.py
v_xticksi
¶
V_XTICKSI - Label the x-axis of a plot using SI multipliers.
v_xticksi
¶
Label the x-axis of a plot using SI multipliers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
return_prefix
|
bool
|
If True, return a global SI prefix string that can be incorporated into the axis label. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
The global SI prefix (only if return_prefix=True). |
Examples:
>>> import matplotlib.pyplot as plt
>>> plt.plot([0, 1000, 2000], [0, 1, 2])
>>> v_xticksi()
>>> # Or with a global prefix:
>>> prefix = v_xticksi(return_prefix=True)
>>> plt.xlabel(f'Frequency ({prefix}Hz)')
Source code in pyvoicebox/v_xticksi.py
v_yticksi
¶
V_YTICKSI - Label the y-axis of a plot using SI multipliers.
v_yticksi
¶
Label the y-axis of a plot using SI multipliers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
return_prefix
|
bool
|
If True, return a global SI prefix string that can be incorporated into the axis label. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
The global SI prefix (only if return_prefix=True). |
Examples:
Source code in pyvoicebox/v_yticksi.py
v_xyzticksi
¶
V_XYZTICKSI - Label an axis of a plot using SI multipliers.
v_xyzticksi
¶
Label an axis of a plot using SI multipliers.
This is the core implementation called by v_xticksi and v_yticksi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax_idx
|
int
|
Axis index: 1 for x-axis, 2 for y-axis, 3 for z-axis. |
required |
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
return_prefix
|
bool
|
If True, try to use a global SI prefix and return it. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
prefix |
str
|
The global SI prefix string (only if return_prefix is True). Empty string if no global prefix could be used. |
Source code in pyvoicebox/v_xyzticksi.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
v_xtickint
¶
V_XTICKINT - Remove non-integer ticks from x-axis.
v_xtickint
¶
Remove non-integer tick marks from the x-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
xtick |
ndarray
|
Array of remaining integer tick positions. |
Source code in pyvoicebox/v_xtickint.py
v_ytickint
¶
V_YTICKINT - Remove non-integer ticks from y-axis.
v_ytickint
¶
Remove non-integer tick marks from the y-axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ytick |
ndarray
|
Array of remaining integer tick positions. |
Source code in pyvoicebox/v_ytickint.py
v_texthvc
¶
V_TEXTHVC - Write text on graph with specified alignment and colour.
v_texthvc
¶
Write text on graph with specified alignment and colour.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float or array_like
|
X-position. If length-2 array [x0, k], positions at x0 + k*axis_width. |
required |
y
|
float or array_like
|
Y-position. If length-2 array [y0, k], positions at y0 + k*axis_height. |
required |
t
|
str
|
Text string to display. |
required |
p
|
str
|
Alignment/colour string 'hvc' where: h = horizontal: l=left, c/m=center, r=right v = vertical: t=top, p=cap, c/m=middle, l=baseline, b=bottom c = colour: r,g,b,c,m,y,k,w If h or v is uppercase, position is normalized (0 to 1). |
None
|
q
|
array_like or str
|
Alternative colour as [r, g, b] or a colour string. |
None
|
r
|
optional
|
Legacy colour argument (for 6-argument compatibility). |
None
|
ax
|
Axes
|
Axes handle. Default is plt.gca(). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
text_obj |
Text
|
The text object. |
Source code in pyvoicebox/v_texthvc.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
v_cblabel
¶
V_CBLABEL - Add a label to a colorbar.
v_cblabel
¶
Add a label to a colorbar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
Label string for the colorbar. |
required |
h
|
matplotlib colorbar, axes, or figure
|
Handle of the colorbar, axis, or figure. If None, searches the current figure for a colorbar. |
None
|
ax
|
Axes
|
The axes to search for a nearby colorbar (alternative to h). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
cb |
matplotlib colorbar or axes
|
Handle of the colorbar that was labelled. |
Source code in pyvoicebox/v_cblabel.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
Number formatting¶
v_sprintsi
¶
V_SPRINTSI - Print value with SI multiplier.
v_sprintsi
¶
Format a number with an SI multiplier prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Value to print. |
required |
d
|
int
|
Decimal places (+ve) or significant digits (-ve). Default -3. |
-3
|
w
|
int
|
Minimum total width. Default 0. |
0
|
u
|
str
|
Unit string. Default ' '. |
' '
|
Returns:
| Name | Type | Description |
|---|---|---|
s |
str
|
Formatted string. |
Source code in pyvoicebox/v_sprintsi.py
v_sprintcpx
¶
V_SPRINTCPX - Format a complex number for printing.
v_sprintcpx
¶
Format a complex number for printing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
complex
|
Complex number to format. |
required |
f
|
str
|
Format string. May include 'i' or 'j' for sqrt(-1) symbol. Default 'g'. |
'g'
|
Returns:
| Name | Type | Description |
|---|---|---|
s |
str
|
Formatted string. |
Source code in pyvoicebox/v_sprintcpx.py
v_bitsprec
¶
V_BITSPREC - Round values to a specified fixed or floating precision.
v_bitsprec
¶
Round values to a specified number of bits precision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array_like
|
Input values. |
required |
n
|
int
|
Number of bits. |
None
|
mode
|
str
|
Mode string 'uvw' where: u: 's' = significant bits (default), 'f' = fixed point v: 'n' = nearest, 'p' = toward +inf, 'm' = toward -inf, 'z' = toward zero w: 'e' = even (default), 'o' = odd, 'a' = away from zero, 'p'/'m' = as v |
'sne'
|
Returns:
| Name | Type | Description |
|---|---|---|
y |
ndarray
|
Rounded values. |