{ "cells": [ { "cell_type": "markdown", "id": "american-attachment", "metadata": {}, "source": [ "# Plot Margins\n", "\n", "`plot_margin` parameter in `theme()` allows to change the margin areas of a plot using the `margin()` function." ] }, { "cell_type": "code", "execution_count": 1, "id": "announced-investigation", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "corporate-passion", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "1aadd36a-0358-4edf-9ded-4b8f0ff0060a", "metadata": {}, "outputs": [], "source": [ "np.random.seed(42)\n", "data = {'x': np.random.randint(10, size=100)}\n", "\n", "p = ggplot(data, aes(x='x')) + geom_bar() + ggtitle(\"Bar Сhart\") + \\\n", " theme(plot_background=element_rect(size = 6))" ] }, { "cell_type": "markdown", "id": "8d2d1e77-e38d-42d1-8726-7dd0b67925ec", "metadata": {}, "source": [ "#### Plot without Margins" ] }, { "cell_type": "code", "execution_count": 4, "id": "51e28dc7-d549-42cb-bcb5-a2389b369f32", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p" ] }, { "cell_type": "markdown", "id": "757bad9f-0663-49b7-ae57-4a61c14121fb", "metadata": {}, "source": [ "#### Plot with Margins" ] }, { "cell_type": "code", "execution_count": 5, "id": "voluntary-estate", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(plot_margin=margin(t=20, # Top\n", " r=10, # Right\n", " b=10, # Bottom\n", " l=10)) # Left " ] } ], "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.18" } }, "nbformat": 4, "nbformat_minor": 5 }