{ "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": { "execution": { "iopub.execute_input": "2024-04-26T12:08:40.380853Z", "iopub.status.busy": "2024-04-26T12:08:40.380853Z", "iopub.status.idle": "2024-04-26T12:08:41.370413Z", "shell.execute_reply": "2024-04-26T12:08:41.370413Z" } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "corporate-passion", "metadata": { "execution": { "iopub.execute_input": "2024-04-26T12:08:41.371462Z", "iopub.status.busy": "2024-04-26T12:08:41.371462Z", "iopub.status.idle": "2024-04-26T12:08:41.386306Z", "shell.execute_reply": "2024-04-26T12:08:41.386306Z" } }, "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": { "execution": { "iopub.execute_input": "2024-04-26T12:08:41.386306Z", "iopub.status.busy": "2024-04-26T12:08:41.386306Z", "iopub.status.idle": "2024-04-26T12:08:41.496845Z", "shell.execute_reply": "2024-04-26T12:08:41.496845Z" } }, "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": { "execution": { "iopub.execute_input": "2024-04-26T12:08:41.496845Z", "iopub.status.busy": "2024-04-26T12:08:41.496845Z", "iopub.status.idle": "2024-04-26T12:08:41.528140Z", "shell.execute_reply": "2024-04-26T12:08:41.528140Z" } }, "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": { "execution": { "iopub.execute_input": "2024-04-26T12:08:41.528140Z", "iopub.status.busy": "2024-04-26T12:08:41.528140Z", "iopub.status.idle": "2024-04-26T12:08:41.543764Z", "shell.execute_reply": "2024-04-26T12:08:41.543764Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p + theme(plot_margin=[20, # Top\n", " 10, # Right\n", " 10, # Bottom\n", " 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.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }