{ "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": [ "