Convert points into lines of text for an SVG plot Examples -------- >>> svg_lines([0, 1], [0, 0], [10, 11], [1, 1]) # doctest: +NORMALIZE_WHITESPACE [' ', ' <line x1="1" y1="0" x2="11" y2="1" style="stroke-width:2"
(x1, y1, x2, y2, max_n=20)
| 178 | |
| 179 | |
| 180 | def svg_lines(x1, y1, x2, y2, max_n=20): |
| 181 | """Convert points into lines of text for an SVG plot |
| 182 | |
| 183 | Examples |
| 184 | -------- |
| 185 | >>> svg_lines([0, 1], [0, 0], [10, 11], [1, 1]) # doctest: +NORMALIZE_WHITESPACE |
| 186 | [' <line x1="0" y1="0" x2="10" y2="1" style="stroke-width:2" />', |
| 187 | ' <line x1="1" y1="0" x2="11" y2="1" style="stroke-width:2" />'] |
| 188 | """ |
| 189 | n = len(x1) |
| 190 | |
| 191 | if n > max_n: |
| 192 | indices = np.linspace(0, n - 1, max_n, dtype="int") |
| 193 | else: |
| 194 | indices = range(n) |
| 195 | |
| 196 | lines = [ |
| 197 | ' <line x1="{}" y1="{}" x2="{}" y2="{}" />'.format( |
| 198 | int(x1[i]), int(y1[i]), int(x2[i]), int(y2[i]) |
| 199 | ) |
| 200 | for i in indices |
| 201 | ] |
| 202 | |
| 203 | lines[0] = lines[0].replace(" /", ' style="stroke-width:2" /') |
| 204 | lines[-1] = lines[-1].replace(" /", ' style="stroke-width:2" /') |
| 205 | return lines |
| 206 | |
| 207 | |
| 208 | def svg_grid(x, y, offset=(0, 0), skew=(0, 0), size=200): |