Create lines of SVG text that show a grid Parameters ---------- x: numpy.ndarray y: numpy.ndarray offset: tuple translational displacement of the grid in SVG coordinates skew: tuple
(x, y, offset=(0, 0), skew=(0, 0), size=200)
| 206 | |
| 207 | |
| 208 | def svg_grid(x, y, offset=(0, 0), skew=(0, 0), size=200): |
| 209 | """Create lines of SVG text that show a grid |
| 210 | |
| 211 | Parameters |
| 212 | ---------- |
| 213 | x: numpy.ndarray |
| 214 | y: numpy.ndarray |
| 215 | offset: tuple |
| 216 | translational displacement of the grid in SVG coordinates |
| 217 | skew: tuple |
| 218 | """ |
| 219 | # Horizontal lines |
| 220 | x1 = np.zeros_like(y) + offset[0] |
| 221 | y1 = y + offset[1] |
| 222 | x2 = np.full_like(y, x[-1]) + offset[0] |
| 223 | y2 = y + offset[1] |
| 224 | |
| 225 | if skew[0]: |
| 226 | y2 += x.max() * skew[0] |
| 227 | if skew[1]: |
| 228 | x1 += skew[1] * y |
| 229 | x2 += skew[1] * y |
| 230 | |
| 231 | min_x = min(x1.min(), x2.min()) |
| 232 | min_y = min(y1.min(), y2.min()) |
| 233 | max_x = max(x1.max(), x2.max()) |
| 234 | max_y = max(y1.max(), y2.max()) |
| 235 | max_n = size // 6 |
| 236 | |
| 237 | h_lines = ["", " <!-- Horizontal lines -->"] + svg_lines(x1, y1, x2, y2, max_n) |
| 238 | |
| 239 | # Vertical lines |
| 240 | x1 = x + offset[0] |
| 241 | y1 = np.zeros_like(x) + offset[1] |
| 242 | x2 = x + offset[0] |
| 243 | y2 = np.full_like(x, y[-1]) + offset[1] |
| 244 | |
| 245 | if skew[0]: |
| 246 | y1 += skew[0] * x |
| 247 | y2 += skew[0] * x |
| 248 | if skew[1]: |
| 249 | x2 += skew[1] * y.max() |
| 250 | |
| 251 | v_lines = ["", " <!-- Vertical lines -->"] + svg_lines(x1, y1, x2, y2, max_n) |
| 252 | |
| 253 | color = "ECB172" if len(x) < max_n and len(y) < max_n else "8B4903" |
| 254 | corners = f"{x1[0]},{y1[0]} {x1[-1]},{y1[-1]} {x2[-1]},{y2[-1]} {x2[0]},{y2[0]}" |
| 255 | rect = [ |
| 256 | "", |
| 257 | " <!-- Colored Rectangle -->", |
| 258 | f' <polygon points="{corners}" style="fill:#{color}A0;stroke-width:0"/>', |
| 259 | ] |
| 260 | |
| 261 | return h_lines + v_lines + rect, (min_x, max_x, min_y, max_y) |
| 262 | |
| 263 | |
| 264 | def svg_1d(chunks, sizes=None, **kwargs): |