{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "68a8ec84-7d7a-4145-92ca-e35bae9ffe92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple\n", "Collecting svgwrite\n", " Downloading https://www.piwheels.org/simple/svgwrite/svgwrite-1.4.1-py3-none-any.whl (66 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.0/67.0 KB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: svgwrite\n", "Successfully installed svgwrite-1.4.1\n" ] } ], "source": [ "!pip install svgwrite" ] }, { "cell_type": "code", "execution_count": 9, "id": "4d5a776b-5e07-498d-ade3-310bd5d29b22", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Test" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import svgwrite\n", "from IPython.core.display import SVG, display\n", "\n", "dwg = svgwrite.Drawing('test.svg', profile='tiny', size=(595, 842) )\n", "dwg.add(dwg.line((0, 0), (10, 50), stroke=svgwrite.rgb(10, 10, 16, '%')))\n", "dwg.add(dwg.text('Test', insert=(0, 0.2)))\n", "dwg.save()\n", "\n", "display(SVG(filename=f'test.svg'))" ] }, { "cell_type": "code", "execution_count": 41, "id": "93b6030a-22e5-44a8-b261-26d64112eb92", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import svgwrite\n", "from svgwrite import cm, mm\n", "\n", "width = 210\n", "height = 297\n", "\n", "rows = 6\n", "columns = 4\n", "\n", "cell_size = (width/columns, height/rows)\n", "\n", "color = svgwrite.rgb(0,0,0, '%')\n", "background = svgwrite.rgb(100,95,95,'%')\n", "\n", "\n", "sheet = svgwrite.Drawing('map.svg', profile='tiny', size=(width * mm, height * mm))\n", "# sheet.add(sheet.rect((0,0), (width * mm, height * mm), fill=background))\n", "\n", "grid = sheet.add(sheet.g(id='grid', stroke='gainsboro')).dasharray([10, 10])\n", "\n", "\n", "for row in range(rows + 1):\n", " y = cell_size[1] * row \n", " grid.add(sheet.line((0, y * mm), (width * mm, y * mm)))\n", " \n", "for col in range(columns + 1):\n", " x = cell_size[0] * col\n", " grid.add(sheet.line((x * mm, 0), (x * mm,height * mm)))\n", "\n", " \n", " \n", "sheet.save()\n", "display(SVG(filename=f'map.svg'))" ] }, { "cell_type": "code", "execution_count": null, "id": "0e573286-ef9e-42ac-a0e7-2981849a5662", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }