{
 "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": [
       "<svg baseProfile=\"tiny\" height=\"100%\" version=\"1.2\" width=\"100%\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs/><line stroke=\"rgb(10%,10%,16%)\" x1=\"0\" x2=\"10\" y1=\"0\" y2=\"50\"/><text x=\"0\" y=\"0.2\">Test</text></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "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": [
       "<svg baseProfile=\"tiny\" height=\"297mm\" version=\"1.2\" width=\"210mm\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs/><rect fill=\"rgb(100%,95%,95%)\" height=\"297mm\" width=\"210mm\" x=\"0\" y=\"0\"/><g id=\"grid\" stroke=\"gainsboro\" stroke-dasharray=\"10 10\"><line x1=\"0\" x2=\"210mm\" y1=\"0.0mm\" y2=\"0.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"49.5mm\" y2=\"49.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"99.0mm\" y2=\"99.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"148.5mm\" y2=\"148.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"198.0mm\" y2=\"198.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"247.5mm\" y2=\"247.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"297.0mm\" y2=\"297.0mm\"/><line x1=\"0.0mm\" x2=\"0.0mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"52.5mm\" x2=\"52.5mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"105.0mm\" x2=\"105.0mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"157.5mm\" x2=\"157.5mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"210.0mm\" x2=\"210.0mm\" y1=\"0\" y2=\"297mm\"/></g></svg>"
      ],
      "text/plain": [
       "<IPython.core.display.SVG object>"
      ]
     },
     "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
}
