{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualization: Matplotlib & Seaborn\n", "\n", "Matplotlib is Python's primary library for creating static, animated, and interactive visualizations.\n", "\n", "The library is built around two core components:\n", "\n", "**Figure**: The top-level container that holds all plot elements. A figure can contain one or more axes.\n", "\n", "**Axes**: The plotting area where data is displayed. Each axes object includes an x-axis and y-axis (plus z-axis for 3D plots) and provides methods for plotting data points. \n", "\n", "\n", "{width=\"60%\"}\n", "\n", ":::{.callout-note}\n", "Documentation for these packages is available at https://matplotlib.org/stable/ and https://seaborn.pydata.org/api.html.\n", ":::\n", "\n", "We can import Matplotlib as follows" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-19T18:20:48.186669Z", "iopub.status.busy": "2026-01-19T18:20:48.186438Z", "iopub.status.idle": "2026-01-19T18:20:48.615525Z", "shell.execute_reply": "2026-01-19T18:20:48.614961Z" } }, "outputs": [], "source": [ "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Seaborn is built on top of Matplotlib and provides a high-level interface for drawing attractive and informative statistical graphics. We can import Seaborn as follows" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-19T18:20:48.618230Z", "iopub.status.busy": "2026-01-19T18:20:48.617911Z", "iopub.status.idle": "2026-01-19T18:20:50.130399Z", "shell.execute_reply": "2026-01-19T18:20:50.129281Z" } }, "outputs": [], "source": [ "import seaborn as sns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For some examples, we won't need seaborn, but we are importing it here because it has some built-in datasets that we can use for visualization. Let's load one of these datasets:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-19T18:20:50.133301Z", "iopub.status.busy": "2026-01-19T18:20:50.132982Z", "iopub.status.idle": "2026-01-19T18:20:50.150524Z", "shell.execute_reply": "2026-01-19T18:20:50.150039Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | total_bill | \n", "tip | \n", "sex | \n", "smoker | \n", "day | \n", "time | \n", "size | \n", "
|---|---|---|---|---|---|---|---|
| 0 | \n", "16.99 | \n", "1.01 | \n", "Female | \n", "No | \n", "Sun | \n", "Dinner | \n", "2 | \n", "
| 1 | \n", "10.34 | \n", "1.66 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "3 | \n", "
| 2 | \n", "21.01 | \n", "3.50 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "3 | \n", "
| 3 | \n", "23.68 | \n", "3.31 | \n", "Male | \n", "No | \n", "Sun | \n", "Dinner | \n", "2 | \n", "
| 4 | \n", "24.59 | \n", "3.61 | \n", "Female | \n", "No | \n", "Sun | \n", "Dinner | \n", "4 | \n", "