{ "cells": [ { "cell_type": "markdown", "id": "ed4d75f9-7071-4a88-a88d-690f99ef1d1d", "metadata": {}, "source": [ "# Responsive Element Sizing with `size_unit='min'` and `size_unit='max'`\n", "\n", "\n", "These options provide control over element sizing by automatically adapting to plot dimensions and aspect ratios.\n", "\n", "The `'min'` option is particularly useful for ensuring elements fit within plot boundaries regardless of the plot's size or form factor." ] }, { "cell_type": "code", "execution_count": 1, "id": "78964b74-1284-4f63-82dd-c7f1872b6025", "metadata": {}, "outputs": [], "source": [ "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "945229c6-c120-45e1-85b9-06383e55e918", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "e3156726-e9f3-4ff5-92b8-caa8020cc8a7", "metadata": {}, "outputs": [], "source": [ "data = {'name': ['a', 'b', 'c', 'd', 'b'], 'value': [40, 90, 10, 50, 20]}\n" ] }, { "cell_type": "markdown", "id": "d1f11b35-2fef-4659-b904-ac78c11ba3c5", "metadata": {}, "source": [ "#### `size_unit='min'`" ] }, { "cell_type": "code", "execution_count": 4, "id": "5ca804b3-8511-4603-b17b-621e0afbaf3d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pie_size_unit_min = (ggplot(data) \n", " + geom_pie(aes(fill='name', weight='value'), \n", " size=.95, # <-- set size in relative units\n", " size_unit='min') # <-- set the size unit to the smaller of the unit steps along the x and y axes\n", " )\n", "ggbunch([\n", " pie_size_unit_min,\n", " pie_size_unit_min,\n", " pie_size_unit_min,\n", " pie_size_unit_min,\n", " ],\n", " regions=[\n", " (0, 0, 0.6, 0.4),\n", " (0.6, 0, 0.4, 0.7),\n", " (0.1, 0.4, 0.3, 0.6),\n", " (0.4, 0.7, 0.6, 0.3),\n", " ]\n", " \n", ") + theme_bw() + ggsize(800, 600)" ] }, { "cell_type": "markdown", "id": "6401174f-4398-45a0-bd0c-ad01ee6c13bf", "metadata": {}, "source": [ "#### `size_unit='max'`" ] }, { "cell_type": "code", "execution_count": 5, "id": "6fb15c47-09a5-4645-99ae-e6be7055077a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pie_size_unit_max = (ggplot(data) \n", " + geom_pie(aes(fill='name', weight='value'), \n", " size=.95, # <-- set size in relative units\n", " size_unit='max') # <-- set the size unit to the larger of the unit steps along the x and y axes\n", " )\n", "ggbunch([\n", " pie_size_unit_max,\n", " pie_size_unit_max,\n", " pie_size_unit_max,\n", " pie_size_unit_max,\n", " ],\n", " regions=[\n", " (0, 0, 0.6, 0.4),\n", " (0.6, 0, 0.4, 0.7),\n", " (0.1, 0.4, 0.3, 0.6),\n", " (0.4, 0.7, 0.6, 0.3),\n", " ]\n", " \n", ") + theme_bw() + ggsize(800, 600)" ] } ], "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.9.23" } }, "nbformat": 4, "nbformat_minor": 5 }