{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "a181905e-ddbd-416e-8e10-20210d57f4bd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lets_plot import *\n", "LetsPlot.setup_html()\n", "\n", "from lets_plot.plot.coord import coord_polar" ] }, { "cell_type": "code", "execution_count": 2, "id": "bd55dece-a599-4a1e-939e-3779c4a0adfc", "metadata": {}, "outputs": [], "source": [ "hours = list(map(lambda v: '{:02d}:00'.format(v), range(12)))\n", "p = ggplot() \\\n", " + geom_point(aes(x=hours)) \\\n", " + theme_grey()" ] }, { "cell_type": "markdown", "id": "afd30d53-4a7a-46f7-9394-233e7be0441c", "metadata": {}, "source": [ "# Linear coordinate system \n", "In linear coordinate systems `inset` acts as a margin, moving the panel boundaries within the plot:" ] }, { "cell_type": "code", "execution_count": 3, "id": "75f5e483-d09c-4ab5-9431-591e5d74b7d8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "gggrid([\n", " p,\n", " p + theme(panel_inset=15)\n", "])" ] }, { "cell_type": "markdown", "id": "b4f60f05-f388-4fab-8bec-cb347612d009", "metadata": {}, "source": [ "# Polar coordinate system\n", "Default inset may cause tick labels overlapping in polar coordinate system. \n", "The `panel_inset` parameter acts as a margin and can be used to create space between the axis and the panel:" ] }, { "cell_type": "code", "execution_count": 4, "id": "6f8f448b-6033-4e79-b730-51aa45edbc2f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "inset = [0, 35, 0, 35]\n", "polar = coord_polar(xlim=[0, 12])\n", "gggrid([\n", " p + polar,\n", " p + theme(panel_inset=inset) + polar,\n", "])" ] }, { "cell_type": "markdown", "id": "fa972fc6-485d-475b-b0d6-717dee74c2bf", "metadata": {}, "source": [ "# Parameter `transform_bkgr` \n", "\n", "When using the `transform_bkgr` parameter, the panel is not transformed into a circle, but remains a rectangle. This behaviour is similar to `ggplot2`. \n", "In this case, `panel_inset` acts as padding, pushing the content into the panel:" ] }, { "cell_type": "code", "execution_count": 5, "id": "eace351b-a6ec-4632-8d16-e0fd8d9a1ae3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "polar = coord_polar(xlim=[0, 12], transform_bkgr=False)\n", "gggrid([\n", " p + polar,\n", " p + theme(panel_inset=inset) + polar\n", "])" ] }, { "cell_type": "markdown", "id": "8ec5dcf8-1663-4ad1-952d-6a0d6b8acf73", "metadata": {}, "source": [ "# `coord_fixed()`\n", "This is how `panel_inset` works in `coord_fixed()`." ] }, { "cell_type": "code", "execution_count": 6, "id": "b5ce48df-6011-49e8-8385-b4a0dcb6448f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "inset = 40\n", "p \\\n", " + scale_x_continuous(position='both') \\\n", " + scale_y_continuous(position='both') \\\n", " + coord_fixed() \\\n", " + ggtitle('coord_fixed() + inset=' + str(inset)) \\\n", " + theme(panel_inset=inset) \n" ] } ], "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.8.15" } }, "nbformat": 4, "nbformat_minor": 5 }