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