{ "cells": [ { "cell_type": "markdown", "id": "7b0f000e-193a-4e9d-bdc6-c87c509136f0", "metadata": {}, "source": [ "# Parameters `width_unit`/`height_unit`" ] }, { "cell_type": "code", "execution_count": 1, "id": "11a6319f-f3d1-4de9-8475-84d05e336c25", "metadata": { "tags": [] }, "outputs": [], "source": [ "from math import sqrt\n", "\n", "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "b8631866-1009-4fd9-b55d-491bad87d5b6", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "id": "6bf67d44-5660-4b66-9624-320036aae29e", "metadata": {}, "source": [ "## `geom_errorbar()`" ] }, { "cell_type": "markdown", "id": "4b02a0ac-b389-417a-b8c5-c3ce0a5399f9", "metadata": {}, "source": [ "### [Issue #1288](https://github.com/JetBrains/lets-plot/issues/1288) - Allow absolute width for geom_errorbar (and possibly others)" ] }, { "cell_type": "code", "execution_count": 3, "id": "150d4b60-9ad2-4360-b4f3-7621d15fca08", "metadata": {}, "outputs": [], "source": [ "def get_diff_data():\n", " n = 16\n", " dy = 100\n", " xs = [2 * i for i in range(n)]\n", " return pd.DataFrame({\n", " 'x': xs,\n", " 'ymin': [dy + i % 4 for i in range(n)],\n", " 'lower': [dy + i % 4 + .25 for i in range(n)],\n", " 'upper': [dy + i % 4 + 2.25 for i in range(n)],\n", " 'ymax': [dy + i % 4 + 2.5 for i in range(n)],\n", " 'width_px': [10 * (i % 4 + 1) for i in range(n)]\n", " })\n", "\n", "diff16_df = get_diff_data()\n", "diff4_df = diff16_df.iloc[:4]" ] }, { "cell_type": "code", "execution_count": 4, "id": "4d35e6f1-278a-471f-95a7-658cd05bf3bb", "metadata": {}, "outputs": [], "source": [ "def get_errorbar_plot(df, width=None, width_unit=None):\n", " cat_size = len(df['x'].unique())\n", " return ggplot(df) + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax'),\n", " width=width, width_unit=width_unit) + \\\n", " ggtitle(\"categories count: {0}\\nwidth={1}, width_unit={2}\".format(\n", " cat_size, width, width_unit\n", " ))" ] }, { "cell_type": "code", "execution_count": 5, "id": "76b3ec5e-2a50-4bd7-a90a-ee446b9cf7ca", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " get_errorbar_plot(diff16_df, width=.5),\n", " get_errorbar_plot(diff4_df, width=.5),\n", " get_errorbar_plot(diff16_df, width=5, width_unit='size'),\n", " get_errorbar_plot(diff4_df, width=5, width_unit='size'),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "b0a83390-b3a9-4d97-bd68-6eb465c0135a", "metadata": {}, "source": [ "### Additional tests" ] }, { "cell_type": "code", "execution_count": 6, "id": "e3e389a0-7b1c-4c94-a646-b8a70e2f4500", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax', width='width_px'), width_unit='px') + \\\n", " ggtitle(\"Mapped width (px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='px', width=30) + \\\n", " ggtitle(\"Constant width (30 px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax'), width_unit='px', width=30) + \\\n", " ggtitle(\"Constant width (30 px)\", \"orientation='y'\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='res', width=1) + \\\n", " ggtitle(\"Constant width (1 res)\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='identity', width=2) + \\\n", " ggtitle(\"Constant width (2 identity = 2 axis units)\"),\n", " ggplot(diff4_df) + \\\n", " geom_point(aes(x='x', y='ymax'), size=12, color=\"lightgray\") + \\\n", " geom_errorbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='size', width=12) + \\\n", " ggtitle(\"Constant width (12 sizes = point of size 12)\"),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 7, "id": "ddf6a7a9-9388-4a7f-806c-80afb6d5288c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_diff_test_plot(width, width_unit, coord, geom):\n", " p = ggplot(diff4_df) + \\\n", " geom(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper'),\n", " stat='identity', width_unit=width_unit, width=width) + \\\n", " coord + \\\n", " ggtitle(\"width={w}, width_unit={wu}\\n\\ncoord={c}\".format(\n", " w=width,\n", " wu=width_unit,\n", " c=coord.as_dict()\n", " ))\n", " if width_unit == 'size':\n", " p += geom_point(aes(x='x', y='ymax'), size=12, color=\"gray\", alpha=.25)\n", " return p\n", "\n", "plots = []\n", "for width, width_unit in [(1, 'res'), (2, 'identity'), (50, 'px'), (12, 'size')]:\n", " for coord in [\n", " coord_cartesian(),\n", " coord_fixed(ratio=.5),\n", " coord_flip(),\n", " ]:\n", " plots.append(get_diff_test_plot(width, width_unit, coord, geom_errorbar))\n", "\n", "gggrid(plots, ncol=2) + ggsize(800, 2400)" ] }, { "cell_type": "markdown", "id": "79f702c7-0e4f-464f-b0d6-effcb6cd659b", "metadata": {}, "source": [ "#### Deprecated aesthetics and parameters" ] }, { "cell_type": "code", "execution_count": 8, "id": "73104f3a-8f64-4384-8803-4aff9e715851", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "WARN: using 'height' aesthetic parameter for errorbar was deprecated.\n", " Please, use 'width' aesthetic instead.\n", "WARN: using 'height' aesthetic parameter for errorbar was deprecated.\n", " Please, use 'width' aesthetic instead.\n", "WARN: using 'height_unit' parameter for errorbar was deprecated.\n", " Please, use 'width_unit' parameter instead.\n", "WARN: using 'height_unit' parameter for errorbar was deprecated.\n", " Please, use 'width_unit' parameter instead.\n", "WARN: using 'height_unit' parameter for errorbar was deprecated.\n", " Please, use 'width_unit' parameter instead.\n", "WARN: using 'height' parameter for errorbar was deprecated.\n", " Please, use 'width' parameter instead.\n", "WARN: using 'height' parameter for errorbar was deprecated.\n", " Please, use 'width' parameter instead.\n" ] }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax', height='width_px'), width_unit='px') + \\\n", " ggtitle(\"aes(height='width_px')\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax', width='width_px', height='width_px'), width_unit='px') + \\\n", " ggtitle(\"aes(width='width_px', height='width_px')\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax', width='width_px'), height_unit='px') + \\\n", " ggtitle(\"aes(width='width_px'), height_unit='px'\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax'), width=30, height_unit='px') + \\\n", " ggtitle(\"width=30, height_unit='px'\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax'), width=30, height_unit='px', width_unit='px') + \\\n", " ggtitle(\"width=30, height_unit='px', width_unit='px'\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax'), height=30, width_unit='px') + \\\n", " ggtitle(\"height=30\"),\n", " ggplot(diff4_df) + \\\n", " geom_errorbar(aes(y='x', xmin='ymin', xmax='ymax'), width=50, height=10, width_unit='px') + \\\n", " ggtitle(\"width=50 and height=10\"),\n", "], ncol=2)" ] }, { "cell_type": "markdown", "id": "23bc0b41-e248-4d10-8acb-cd0af0e7bb7a", "metadata": {}, "source": [ "## `geom_boxplot()`/`geom_crossbar()`" ] }, { "cell_type": "code", "execution_count": 9, "id": "824b52c1-3eb6-46ee-beb2-38e56b0cb8aa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(diff4_df) + \\\n", " geom_boxplot(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper', width='width_px'),\n", " stat='identity', width_unit='px') + \\\n", " ggtitle(\"Mapped width (px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_boxplot(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper'),\n", " stat='identity', width_unit='px', width=30) + \\\n", " ggtitle(\"Constant width (30 px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_boxplot(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper'),\n", " stat='identity', width_unit='res', width=1) + \\\n", " ggtitle(\"Constant width (1 res)\"),\n", " ggplot(diff4_df) + \\\n", " geom_boxplot(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper'),\n", " stat='identity', width_unit='identity', width=2) + \\\n", " ggtitle(\"Constant width (2 identity = 2 axis units)\"),\n", " ggplot(diff4_df) + \\\n", " geom_point(aes(x='x', y='upper'), size=12, color=\"lightgray\") + \\\n", " geom_boxplot(aes(x='x', ymin='ymin', ymax='ymax', lower='lower', upper='upper'),\n", " stat='identity', width_unit='size', width=12) + \\\n", " ggtitle(\"Constant width (12 sizes = point of size 12)\"),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 10, "id": "abaf3028-c166-457a-9361-43ae911fcb6b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plots = []\n", "for width, width_unit in [(1, 'res'), (2, 'identity'), (50, 'px'), (12, 'size')]:\n", " for coord in [\n", " coord_cartesian(),\n", " coord_fixed(ratio=.5),\n", " coord_flip(),\n", " ]:\n", " plots.append(get_diff_test_plot(width, width_unit, coord, geom_boxplot))\n", "\n", "gggrid(plots, ncol=2) + ggsize(800, 2400)" ] }, { "cell_type": "code", "execution_count": 11, "id": "c478c666-62d6-47d1-a252-29691eac5626", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(diff4_df) + \\\n", " geom_crossbar(aes(x='x', ymin='ymin', ymax='ymax', width='width_px'), width_unit='px') + \\\n", " ggtitle(\"Mapped width (px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_crossbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='px', width=30) + \\\n", " ggtitle(\"Constant width (30 px)\"),\n", " ggplot(diff4_df) + \\\n", " geom_crossbar(aes(y='x', xmin='ymin', xmax='ymax'), width_unit='px', width=30) + \\\n", " ggtitle(\"Constant width (30 px)\", \"orientation='y'\"),\n", " ggplot(diff4_df) + \\\n", " geom_crossbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='res', width=1) + \\\n", " ggtitle(\"Constant width (1 res)\"),\n", " ggplot(diff4_df) + \\\n", " geom_crossbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='identity', width=2) + \\\n", " ggtitle(\"Constant width (2 identity = 2 axis units)\"),\n", " ggplot(diff4_df) + \\\n", " geom_point(aes(x='x', y='ymax'), size=12, color=\"lightgray\") + \\\n", " geom_crossbar(aes(x='x', ymin='ymin', ymax='ymax'), width_unit='size', width=12) + \\\n", " ggtitle(\"Constant width (12 sizes = point of size 12)\"),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 12, "id": "1450aaed-54e1-4861-8a9e-67adef722431", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plots = []\n", "for width, width_unit in [(1, 'res'), (2, 'identity'), (50, 'px'), (12, 'size')]:\n", " for coord in [\n", " coord_cartesian(),\n", " coord_fixed(ratio=.5),\n", " coord_flip(),\n", " ]:\n", " plots.append(get_diff_test_plot(width, width_unit, coord, geom_crossbar))\n", "\n", "gggrid(plots, ncol=2) + ggsize(800, 2400)" ] }, { "cell_type": "markdown", "id": "2ba7ed09-c7bd-4d95-814b-f06b994a8271", "metadata": {}, "source": [ "## `geom_tile()`" ] }, { "cell_type": "markdown", "id": "25603cfd-9913-424e-a3de-7501bf696b30", "metadata": {}, "source": [ "### Custom `width` with `'identity'` stat" ] }, { "cell_type": "markdown", "id": "a77f7b67-bcfe-4ebe-a9b0-e7f19bde6383", "metadata": {}, "source": [ "Suppose we have the following hand-calculated statistics for `binwidth=[4, 4]`:" ] }, { "cell_type": "code", "execution_count": 13, "id": "473982b3-5955-461c-89db-7f214908688b", "metadata": {}, "outputs": [], "source": [ "tile_stat_data = {\n", " 'x': [2, 2, 6, 10, 10],\n", " 'y': [2, 10, 2, 2, 10],\n", " 'mean': [1.2, 1.8, 0.8, 1.2, 0.6],\n", " 'width_px': [10, 20, 30, 40, 50],\n", " 'height_px': [10, 20, 30, 40, 50],\n", "}" ] }, { "cell_type": "markdown", "id": "196e3df5-8ddc-494a-96e2-7ecc1c8a1183", "metadata": {}, "source": [ "And we want to plot this data using `geom_tile()` (or `geom_bin2d(stat='identity')`):" ] }, { "cell_type": "code", "execution_count": 14, "id": "1ca591db-bab0-4968-b3ab-70edbd9427b7", "metadata": {}, "outputs": [], "source": [ "def get_tile_plot(width=None, height=None, width_unit=None, height_unit=None):\n", " return ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'), width=width, height=height,\n", " width_unit=width_unit, height_unit=height_unit) + \\\n", " ggtitle(\"Supposed binwidth: [4, 4]\\nwidth={w}, width_unit={wu}\\nheight={h}, height_unit={hu}\".format(\n", " w=width, wu=width_unit,\n", " h=height, hu=height_unit,\n", " ))" ] }, { "cell_type": "code", "execution_count": 15, "id": "86aa18f0-693c-45ed-857b-cd3cc9d93101", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " get_tile_plot(),\n", " get_tile_plot(width=1, height=.5),\n", " get_tile_plot(width=4, height=4, width_unit='identity', height_unit='identity'),\n", "], ncol=3)" ] }, { "cell_type": "markdown", "id": "bec38372-d69d-4a3a-b818-9205aed21801", "metadata": {}, "source": [ "### Additional tests" ] }, { "cell_type": "code", "execution_count": 16, "id": "2f0a4ae8-b1b0-4dcd-bf9e-5ac72f895909", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean', width='width_px', height='height_px'),\n", " width_unit='px', height_unit='px') + \\\n", " ggtitle(\"Mapped width and height (px)\"),\n", " ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'),\n", " width=40, height=40,\n", " width_unit='px', height_unit='px') + \\\n", " ggtitle(\"Constant width and height (40 px)\"),\n", " ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'),\n", " width=1, height=1,\n", " width_unit='res', height_unit='res') + \\\n", " ggtitle(\"Constant width and height (1 res)\"),\n", " ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'),\n", " width=3, height=3,\n", " width_unit='identity', height_unit='identity') + \\\n", " ggtitle(\"Constant width and height (3 identity = 3 axis units)\"),\n", " ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'),\n", " width=20, height=20,\n", " width_unit='size', height_unit='size') + \\\n", " geom_point(color='gray', size=20) + \\\n", " ggtitle(\"Constant width and height (20 sizes = point of size 20)\"),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 17, "id": "26c021ac-bf99-4fc3-9c4f-a32141ccda8b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_tile_test_plot(width, height, width_unit, height_unit, coord):\n", " return ggplot(tile_stat_data, aes('x', 'y')) + \\\n", " geom_tile(aes(fill='mean'),\n", " width_unit=width_unit, height_unit=height_unit,\n", " width=width, height=height) + \\\n", " geom_point(size=12, color=\"lightgray\") + \\\n", " coord + \\\n", " ggtitle(\"width={w}, width_unit={wu}\\nheight={h}, height_unit={hu}\\n\\ncoord={c}\".format(\n", " w=width,\n", " wu=width_unit,\n", " h=height,\n", " hu=height_unit,\n", " c=coord.as_dict()\n", " ))\n", "\n", "plots = []\n", "for dim, dim_unit in [(1, 'res'), (3, 'identity'), (50, 'px'), (12, 'size')]:\n", " for coord in [\n", " coord_cartesian(),\n", " coord_fixed(ratio=.5),\n", " coord_flip(),\n", " ]:\n", " plots.append(get_tile_test_plot(dim, dim, dim_unit, dim_unit, coord))\n", "\n", "gggrid(plots, ncol=2) + ggsize(800, 2400)" ] }, { "cell_type": "markdown", "id": "2d92ad0f-107d-4e7a-b16d-5fea632d6f60", "metadata": {}, "source": [ "## `geom_hex()`" ] }, { "cell_type": "code", "execution_count": 18, "id": "d699f4d2-3a7d-4403-9a7a-c2d2836e7044", "metadata": {}, "outputs": [], "source": [ "hex_stat_data = {\n", " 'x': [2, 2, 6, 10, 10],\n", " 'y': [v * sqrt(3.0) / 2.0 for v in [2, 10, 2, 2, 10]],\n", " 'v': [1.2, 1.8, 0.8, 1.2, 0.6],\n", " 'width_px': [10, 20, 30, 40, 50],\n", " 'height_px': [10, 20, 30, 40, 50],\n", "}" ] }, { "cell_type": "code", "execution_count": 19, "id": "ff9dda88-3786-40cf-9238-04211f7427c8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v', width='width_px', height='height_px'),\n", " stat='identity',\n", " width_unit='px', height_unit='px') + \\\n", " ggtitle(\"Mapped width and height (px)\"),\n", " ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v'),\n", " stat='identity',\n", " width=40, height=40,\n", " width_unit='px', height_unit='px') + \\\n", " ggtitle(\"Constant width and height (40 px)\"),\n", " ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v'),\n", " stat='identity',\n", " width=0.5, height=0.5,\n", " width_unit='res', height_unit='res') + \\\n", " ggtitle(\"Constant width and height (0.5 res)\"),\n", " ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v'),\n", " stat='identity',\n", " width=4, height=4,\n", " width_unit='identity', height_unit='identity') + \\\n", " ggtitle(\"Constant width and height (4 identity = 4 axis units)\"),\n", " ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v'),\n", " stat='identity',\n", " width=20, height=20,\n", " width_unit='size', height_unit='size') + \\\n", " geom_point(color='gray', size=20) + \\\n", " ggtitle(\"Constant width and height (20 sizes = point of size 20)\"),\n", "], ncol=2)" ] }, { "cell_type": "code", "execution_count": 20, "id": "f7aab408-d4fa-4c55-8720-3fbd4cd68e7f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def get_hex_test_plot(width, height, width_unit, height_unit, coord):\n", " return ggplot(hex_stat_data, aes('x', 'y')) + \\\n", " geom_hex(aes(fill='v'),\n", " stat='identity',\n", " width_unit=width_unit, height_unit=height_unit,\n", " width=width, height=height) + \\\n", " geom_point(size=12, color=\"lightgray\") + \\\n", " coord + \\\n", " ggtitle(\"width={w}, width_unit={wu}\\nheight={h}, height_unit={hu}\\n\\ncoord={c}\".format(\n", " w=width,\n", " wu=width_unit,\n", " h=height,\n", " hu=height_unit,\n", " c=coord.as_dict()\n", " ))\n", "\n", "plots = []\n", "for dim, dim_unit in [(0.5, 'res'), (4, 'identity'), (50, 'px'), (12, 'size')]:\n", " for coord in [\n", " coord_cartesian(),\n", " coord_fixed(ratio=.5),\n", " coord_flip(),\n", " ]:\n", " plots.append(get_hex_test_plot(dim, dim, dim_unit, dim_unit, coord))\n", "\n", "gggrid(plots, ncol=2) + ggsize(800, 2400)" ] } ], "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.16" } }, "nbformat": 4, "nbformat_minor": 5 }