{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f0127a7f-f49d-4814-9918-cb0c93851b9c", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "0bdfadcf-f5ca-42c2-b022-0c4f40acdbaa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "0421835e-3beb-45d9-ab48-d787dd315073", "metadata": {}, "outputs": [], "source": [ "def plot(value, label_format, exponent_format, *, text_size=None, color=None):\n", " return ggplot() + \\\n", " geom_text(x=0, label=value, size=text_size, label_format=label_format) + \\\n", " theme_void() + \\\n", " theme(\n", " exponent_format=exponent_format,\n", " plot_background=element_rect(color=\"white\", fill=color, size=1),\n", " )\n", "\n", "class Cell:\n", "\n", " def __init__(self, row, col, value, label_format, exponent_format, color):\n", " self.row = row\n", " self.col = col\n", " self.value = value\n", " self.format = label_format\n", " self.exponent_format = exponent_format\n", " self.color = color\n", "\n", "class Table:\n", "\n", " DEF_COLOR = \"#eeeeee\"\n", "\n", " cells = []\n", "\n", " def __init__(self, width, height, text_size):\n", " self.width = width\n", " self.height = height\n", " self.text_size = text_size\n", "\n", " def add(self, row, col, value, *, exponent_format=None, color=DEF_COLOR):\n", " if exponent_format is None:\n", " label_format = \".14~f\"\n", " else:\n", " label_format = \"g\"\n", " self.cells.append(Cell(row, col, value, label_format, exponent_format, color))\n", "\n", " def plot(self):\n", " bunch = GGBunch()\n", " for cell in self.cells:\n", " p = plot(cell.value, cell.format, cell.exponent_format, text_size=self.text_size, color=cell.color)\n", " bunch.add_plot(p, cell.col * self.width, cell.row * self.height, self.width, self.height)\n", " return bunch" ] }, { "cell_type": "code", "execution_count": 4, "id": "40a3faa6-8621-489b-bd2a-ef64e4c626d2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "header_color = \"#dddddd\"\n", "\n", "table = Table(120, 60, 10)\n", "\n", "table.add(0, 0, \"limits\", color=header_color)\n", "table.add(0, 1, \"value\", color=header_color)\n", "table.add(0, 2, \"'e'\", color=header_color)\n", "table.add(0, 3, \"'pow'\", color=header_color)\n", "table.add(0, 4, \"'pow_full'\", color=header_color)\n", "\n", "for r in range(1, 16):\n", " table.add(r, 0, \"default\" if r == 8 else \"\")\n", "\n", "table.add(1, 1, 0.0000001)\n", "table.add(1, 2, 0.0000001, exponent_format='e')\n", "table.add(1, 3, 0.0000001, exponent_format='pow')\n", "table.add(1, 4, 0.0000001, exponent_format='pow_full')\n", "\n", "table.add(2, 1, 0.000001)\n", "table.add(2, 2, 0.000001, exponent_format='e')\n", "table.add(2, 3, 0.000001, exponent_format='pow')\n", "table.add(2, 4, 0.000001, exponent_format='pow_full')\n", "\n", "table.add(3, 1, 0.1)\n", "table.add(3, 2, 0.1, exponent_format='e')\n", "table.add(3, 3, 0.1, exponent_format='pow')\n", "table.add(3, 4, 0.1, exponent_format='pow_full')\n", "\n", "table.add(4, 1, 1)\n", "table.add(4, 2, 1, exponent_format='e')\n", "table.add(4, 3, 1, exponent_format='pow')\n", "table.add(4, 4, 1, exponent_format='pow_full')\n", "\n", "table.add(5, 1, 10)\n", "table.add(5, 2, 10, exponent_format='e')\n", "table.add(5, 3, 10, exponent_format='pow')\n", "table.add(5, 4, 10, exponent_format='pow_full')\n", "\n", "table.add(6, 1, 100000)\n", "table.add(6, 2, 100000, exponent_format='e')\n", "table.add(6, 3, 100000, exponent_format='pow')\n", "table.add(6, 4, 100000, exponent_format='pow_full')\n", "\n", "table.add(7, 1, 1000000)\n", "table.add(7, 2, 1000000, exponent_format='e')\n", "table.add(7, 3, 1000000, exponent_format='pow')\n", "table.add(7, 4, 1000000, exponent_format='pow_full')\n", "\n", "table.add(8, 1, 0.0000002)\n", "table.add(8, 2, 0.0000002, exponent_format='e')\n", "table.add(8, 3, 0.0000002, exponent_format='pow')\n", "table.add(8, 4, 0.0000002, exponent_format='pow_full')\n", "\n", "table.add(9, 1, 0.000002)\n", "table.add(9, 2, 0.000002, exponent_format='e')\n", "table.add(9, 3, 0.000002, exponent_format='pow')\n", "table.add(9, 4, 0.000002, exponent_format='pow_full')\n", "\n", "table.add(10, 1, 200000)\n", "table.add(10, 2, 200000, exponent_format='e')\n", "table.add(10, 3, 200000, exponent_format='pow')\n", "table.add(10, 4, 200000, exponent_format='pow_full')\n", "\n", "table.add(11, 1, 2000000)\n", "table.add(11, 2, 2000000, exponent_format='e')\n", "table.add(11, 3, 2000000, exponent_format='pow')\n", "table.add(11, 4, 2000000, exponent_format='pow_full')\n", "\n", "table.add(12, 1, -1000000)\n", "table.add(12, 2, -1000000, exponent_format='e')\n", "table.add(12, 3, -1000000, exponent_format='pow')\n", "table.add(12, 4, -1000000, exponent_format='pow_full')\n", "\n", "table.add(13, 1, -0.0000001)\n", "table.add(13, 2, -0.0000001, exponent_format='e')\n", "table.add(13, 3, -0.0000001, exponent_format='pow')\n", "table.add(13, 4, -0.0000001, exponent_format='pow_full')\n", "\n", "table.add(14, 1, -2000000)\n", "table.add(14, 2, -2000000, exponent_format='e')\n", "table.add(14, 3, -2000000, exponent_format='pow')\n", "table.add(14, 4, -2000000, exponent_format='pow_full')\n", "\n", "table.add(15, 1, -0.0000002)\n", "table.add(15, 2, -0.0000002, exponent_format='e')\n", "table.add(15, 3, -0.0000002, exponent_format='pow')\n", "table.add(15, 4, -0.0000002, exponent_format='pow_full')\n", "\n", "for c in range(5):\n", " table.add(16, c, \"\", color=\"white\")\n", "\n", "table.add(17, 0, \"limits\", color=header_color)\n", "table.add(17, 1, \"value\", color=header_color)\n", "table.add(17, 2, \"'e'\", color=header_color)\n", "table.add(17, 3, \"'pow'\", color=header_color)\n", "table.add(17, 4, \"'pow_full'\", color=header_color)\n", "\n", "for r in range(18, 27):\n", " table.add(r, 0, \"(-2, 3)\" if r == 22 else \"\")\n", "\n", "table.add(18, 1, 0.01)\n", "table.add(18, 2, 0.01, exponent_format=('e', -2, 3))\n", "table.add(18, 3, 0.01, exponent_format=('pow', -2, 3))\n", "table.add(18, 4, 0.01, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(19, 1, 0.1)\n", "table.add(19, 2, 0.1, exponent_format=('e', -2, 3))\n", "table.add(19, 3, 0.1, exponent_format=('pow', -2, 3))\n", "table.add(19, 4, 0.1, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(20, 1, 1)\n", "table.add(20, 2, 1, exponent_format=('e', -2, 3))\n", "table.add(20, 3, 1, exponent_format=('pow', -2, 3))\n", "table.add(20, 4, 1, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(21, 1, 100)\n", "table.add(21, 2, 100, exponent_format=('e', -2, 3))\n", "table.add(21, 3, 100, exponent_format=('pow', -2, 3))\n", "table.add(21, 4, 100, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(22, 1, 1000)\n", "table.add(22, 2, 1000, exponent_format=('e', -2, 3))\n", "table.add(22, 3, 1000, exponent_format=('pow', -2, 3))\n", "table.add(22, 4, 1000, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(23, 1, 0.02)\n", "table.add(23, 2, 0.02, exponent_format=('e', -2, 3))\n", "table.add(23, 3, 0.02, exponent_format=('pow', -2, 3))\n", "table.add(23, 4, 0.02, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(24, 1, 0.2)\n", "table.add(24, 2, 0.2, exponent_format=('e', -2, 3))\n", "table.add(24, 3, 0.2, exponent_format=('pow', -2, 3))\n", "table.add(24, 4, 0.2, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(25, 1, 200)\n", "table.add(25, 2, 200, exponent_format=('e', -2, 3))\n", "table.add(25, 3, 200, exponent_format=('pow', -2, 3))\n", "table.add(25, 4, 200, exponent_format=('pow_full', -2, 3))\n", "\n", "table.add(26, 1, 2000)\n", "table.add(26, 2, 2000, exponent_format=('e', -2, 3))\n", "table.add(26, 3, 2000, exponent_format=('pow', -2, 3))\n", "table.add(26, 4, 2000, exponent_format=('pow_full', -2, 3))\n", "\n", "for c in range(5):\n", " table.add(27, c, \"\", color=\"white\")\n", "\n", "table.add(28, 0, \"limits\", color=header_color)\n", "table.add(28, 1, \"value\", color=header_color)\n", "table.add(28, 2, \"'e'\", color=header_color)\n", "table.add(28, 3, \"'pow'\", color=header_color)\n", "table.add(28, 4, \"'pow_full'\", color=header_color)\n", "\n", "for r in range(29, 38):\n", " table.add(r, 0, \"(0, 0)\" if r == 33 else \"\")\n", "\n", "table.add(29, 1, 0.1)\n", "table.add(29, 2, 0.1, exponent_format=('e', 0, 0))\n", "table.add(29, 3, 0.1, exponent_format=('pow', 0, 0))\n", "table.add(29, 4, 0.1, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(30, 1, 1)\n", "table.add(30, 2, 1, exponent_format=('e', 0, 0))\n", "table.add(30, 3, 1, exponent_format=('pow', 0, 0))\n", "table.add(30, 4, 1, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(31, 1, 10)\n", "table.add(31, 2, 10, exponent_format=('e', 0, 0))\n", "table.add(31, 3, 10, exponent_format=('pow', 0, 0))\n", "table.add(31, 4, 10, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(32, 1, 0.2)\n", "table.add(32, 2, 0.2, exponent_format=('e', 0, 0))\n", "table.add(32, 3, 0.2, exponent_format=('pow', 0, 0))\n", "table.add(32, 4, 0.2, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(33, 1, 2)\n", "table.add(33, 2, 2, exponent_format=('e', 0, 0))\n", "table.add(33, 3, 2, exponent_format=('pow', 0, 0))\n", "table.add(33, 4, 2, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(34, 1, 20)\n", "table.add(34, 2, 20, exponent_format=('e', 0, 0))\n", "table.add(34, 3, 20, exponent_format=('pow', 0, 0))\n", "table.add(34, 4, 20, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(35, 1, -0.1)\n", "table.add(35, 2, -0.1, exponent_format=('e', 0, 0))\n", "table.add(35, 3, -0.1, exponent_format=('pow', 0, 0))\n", "table.add(35, 4, -0.1, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(36, 1, -1)\n", "table.add(36, 2, -1, exponent_format=('e', 0, 0))\n", "table.add(36, 3, -1, exponent_format=('pow', 0, 0))\n", "table.add(36, 4, -1, exponent_format=('pow_full', 0, 0))\n", "\n", "table.add(37, 1, -10)\n", "table.add(37, 2, -10, exponent_format=('e', 0, 0))\n", "table.add(37, 3, -10, exponent_format=('pow', 0, 0))\n", "table.add(37, 4, -10, exponent_format=('pow_full', 0, 0))\n", "\n", "table.plot()" ] } ], "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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }