{ "cells": [ { "cell_type": "markdown", "id": "2a51cb88-6706-4266-a2c0-794dad6ef810", "metadata": {}, "source": [ "# Customizing `geom_pie()`\n", "Two new parameters have been added to the `geom_pie()` function:\n", "\n", "- `direction`: Controls the sector layout, allowing it to be drawn either clockwise or counterclockwise.\n", "- `start`: Specifies the starting angle of the pie chart in degrees." ] }, { "cell_type": "code", "execution_count": 1, "id": "83168fbc-3b0d-4899-998b-5339d4edc47f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "LetsPlot.setup_html()\n", "\n", "data = {\n", " 'name': ['a', 'b', 'c', 'd', 'b'], \n", " 'value': [ 40, 90, 10 , 50, 20]}\n", "p = ggplot(data, aes(fill='name', weight='value')) " ] }, { "cell_type": "markdown", "id": "a7e003fa-b531-498a-abdc-f80aaf1d85ca", "metadata": {}, "source": [ "By default, the first sector is positioned counterclockwise from the start point (12 o’clock), while the remaining sectors are arranged clockwise." ] }, { "cell_type": "code", "execution_count": 2, "id": "d97a17aa-aaa6-4c00-b52e-3d728f12d7b3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_pie(size=.6, size_unit='x') + ggtitle('geom_pie()')" ] }, { "cell_type": "markdown", "id": "4382ac18-b018-4ed5-97ea-32fa2c7c0a37", "metadata": {}, "source": [ "### `direction`\n", "Use `1` for clockwise (default) or `-1` for counterclockwise." ] }, { "cell_type": "code", "execution_count": 3, "id": "10042f4d-0ff8-44e6-a287-baa77c8c3088", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + geom_pie(size=.6, size_unit='x', direction=-1) + ggtitle('geom_pie(direction=-1)')" ] }, { "cell_type": "markdown", "id": "e59fde8d-9125-4026-aaca-cd883ece4f22", "metadata": {}, "source": [ "### `start`\n", "Defines the initial angle in degrees. Setting `start = 0` disables the default layout." ] }, { "cell_type": "code", "execution_count": 4, "id": "2070d067-21a6-4d22-87d4-26fff9c700ec", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dump_plot(gggrid([\n", " p + geom_pie(size=.9, size_unit='x') + ggtitle('Default'),\n", " p + geom_pie(size=.9, size_unit='x', start=0) + ggtitle('start=0'),\n", " p + geom_pie(size=.9, size_unit='x', start=180) + ggtitle('start=180'),\n", " p + geom_livemap() + geom_pie() + ggtitle('Default'),\n", " p + geom_livemap() + geom_pie(start=0) + ggtitle('start=0'),\n", " p + geom_livemap() + geom_pie(start=180) + ggtitle('start=180')\n", "], ncol=3))" ] }, { "cell_type": "code", "execution_count": 5, "id": "f63ae9fb-537b-4373-86e9-58c9d24a2716", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " p + geom_livemap() + geom_pie() + ggtitle('Default'),\n", " p + geom_livemap() + geom_pie(start=0) + ggtitle('start=0'),\n", " p + geom_livemap() + geom_pie(start=180) + ggtitle('start=180')\n", "])" ] }, { "cell_type": "code", "execution_count": null, "id": "82794766-a3b6-49af-9389-574495d3e470", "metadata": {}, "outputs": [], "source": [] } ], "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.12.8" } }, "nbformat": 4, "nbformat_minor": 5 }