{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Marginal Plots\n", "\n", "A marginal plot is a scatterplot (sometimes a density plot or other bivariate plot) that has histograms, boxplots, or other distribution visualization layers in the margins of the x- and y-axes. \n", "\n", "It allows studying the relationship between 2 numeric variables. \n", "\n", "You can use the `ggmarginal()` function to add marginal layers to a plot." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-03-26T14:31:17.185361Z", "iopub.status.busy": "2024-03-26T14:31:17.185276Z", "iopub.status.idle": "2024-03-26T14:31:17.511161Z", "shell.execute_reply": "2024-03-26T14:31:17.510837Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "from lets_plot import *\n", "from lets_plot.mapping import as_discrete\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-03-26T14:31:17.524278Z", "iopub.status.busy": "2024-03-26T14:31:17.524109Z", "iopub.status.idle": "2024-03-26T14:31:17.525927Z", "shell.execute_reply": "2024-03-26T14:31:17.525735Z" } }, "outputs": [], "source": [ "# The default plot theme and palette.\n", "LetsPlot.set_theme(theme_light())\n", "palette = scale_color_manual(values=[\"#394449\", \"#F7C443\"]) + scale_fill_manual(values=[\"#394449\", \"#F7C443\"])" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-03-26T14:31:17.526958Z", "iopub.status.busy": "2024-03-26T14:31:17.526873Z", "iopub.status.idle": "2024-03-26T14:31:17.529331Z", "shell.execute_reply": "2024-03-26T14:31:17.529136Z" } }, "outputs": [], "source": [ "np.random.seed(0)\n", "\n", "cov0=[[1, -.8], \n", " [-.8, 1]] \n", "cov1=[[ 10, .1],\n", " [.1, .1]]\n", "\n", "x0, y0 = np.random.multivariate_normal(mean=[-2,0], cov=cov0, size=200).T\n", "x1, y1 = np.random.multivariate_normal(mean=[0,1], cov=cov1, size=200).T\n", "\n", "data = dict(\n", " x = np.concatenate((x0,x1)),\n", " y = np.concatenate((y0,y1)),\n", " c = [\"A\"]*200 + [\"B\"]*200\n", ")" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-03-26T14:31:17.530423Z", "iopub.status.busy": "2024-03-26T14:31:17.530279Z", "iopub.status.idle": "2024-03-26T14:31:17.565108Z", "shell.execute_reply": "2024-03-26T14:31:17.564890Z" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "\n", " | Unnamed: 0 | \n", "manufacturer | \n", "model | \n", "displ | \n", "year | \n", "cyl | \n", "trans | \n", "drv | \n", "cty | \n", "hwy | \n", "fl | \n", "class | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "1 | \n", "audi | \n", "a4 | \n", "1.8 | \n", "1999 | \n", "4 | \n", "auto(l5) | \n", "f | \n", "18 | \n", "29 | \n", "p | \n", "compact | \n", "
1 | \n", "2 | \n", "audi | \n", "a4 | \n", "1.8 | \n", "1999 | \n", "4 | \n", "manual(m5) | \n", "f | \n", "21 | \n", "29 | \n", "p | \n", "compact | \n", "
2 | \n", "3 | \n", "audi | \n", "a4 | \n", "2.0 | \n", "2008 | \n", "4 | \n", "manual(m6) | \n", "f | \n", "20 | \n", "31 | \n", "p | \n", "compact | \n", "