You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
8.0 KiB
8.0 KiB
In [1]:
!pip install svgwrite
Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting svgwrite Downloading https://www.piwheels.org/simple/svgwrite/svgwrite-1.4.1-py3-none-any.whl (66 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 67.0/67.0 KB 2.3 MB/s eta 0:00:00 Installing collected packages: svgwrite Successfully installed svgwrite-1.4.1
In [9]:
import svgwrite from IPython.core.display import SVG, display dwg = svgwrite.Drawing('test.svg', profile='tiny', size=(595, 842) ) dwg.add(dwg.line((0, 0), (10, 50), stroke=svgwrite.rgb(10, 10, 16, '%'))) dwg.add(dwg.text('Test', insert=(0, 0.2))) dwg.save() display(SVG(filename=f'test.svg'))
In [102]:
import svgwrite from svgwrite import cm, mm import random # We are using real world sizes in order to match with the post-it placeholders debug = True width = 210 height = 297 rows = 6 columns = 4 cell_size = (width/columns, height/rows) color = svgwrite.rgb(0,0,0, '%') background = svgwrite.rgb(100,95,95,'%') # setup the SVG sheet = svgwrite.Drawing('map.svg', profile='tiny', size=(width * mm, height * mm)) # draw debug helper grid if debug: grid = sheet.add(sheet.g(id='grid', stroke='dodgerblue')).dasharray([5, 5]) for row in range(rows + 1): y = cell_size[1] * row grid.add(sheet.line((0, y * mm), (width * mm, y * mm))) for col in range(columns + 1): x = cell_size[0] * col grid.add(sheet.line((x * mm, 0), (x * mm,height * mm))) # defining the basic shapes def quad_post(x, y): quad_post_size = (50 * mm, 50 * mm) return svgwrite.shapes.Rect(insert=(x,y), size=quad_post_size, stroke=color, fill='none') # adding a group for the post-it placeholders placeholders = sheet.add(sheet.g(id='placeholders', stroke='black')) for row in range(rows + 1): for col in range(columns + 1): if random.random() > 0.5: placeholders.add(quad_post(col * cell_size[1] * mm, row * cell_size[0] * mm)) sheet.save() display(SVG(filename=f'map.svg'))
In [ ]:
In [ ]:
In [ ]: