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