{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9fb5cbba",
   "metadata": {},
   "source": [
    "# Matplotlib\n",
    "\n",
    "This chapter moves from quick pandas plots to explicit Matplotlib control. You will learn the figure-and-axes model, common plotting commands, and the options that make charts reproducible and easier to adapt.\n",
    "\n",
    "- **Figure and Axes**: A figure is the whole canvas and each axes is one chart on it; most Matplotlib commands act on an axes.\n",
    "- **Object-Oriented Plotting**: `fig, ax = plt.subplots()` keeps the figure and axes in variables, so multi-chart dashboards stay clear to build and adjust.\n",
    "- **Plot Types**: Line, bar, scatter, histogram, and box plots each fit a different business question: trend, comparison, relationship, or distribution.\n",
    "- **Chart Controls**: Titles, labels, legends, colors, line styles, axis ranges, and shared axes turn a default plot into a chart a manager can read.\n",
    "- **Saving Figures**: `savefig()` with a suitable size and dpi produces charts ready for reports and slides.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86b16cc2",
   "metadata": {},
   "source": [
    "<h2>Chapter Video</h2>\n",
    "\n",
    "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube-nocookie.com/embed/UO98lJQ3QGI\" title=\"Matplotlib Tutorial (Part 1): Creating and Customizing Our First Plots\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen referrerpolicy=\"strict-origin-when-cross-origin\"></iframe>\n",
    "\n",
    "<div class=\"video-credit\">\n",
    "<p><strong>Video credit:</strong> Schafer, C. (2019, June 10). <em>Matplotlib Tutorial (Part 1): Creating and Customizing Our First Plots</em>. YouTube. <a href=\"https://youtube.com/watch?v=UO98lJQ3QGI\">Watch on YouTube</a>.</p>\n",
    "<p class=\"video-rights\">This embedded video is provided for educational reference only. All rights are retained by the respective copyright holder.</p>\n",
    "</div>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb65f45b",
   "metadata": {},
   "source": [
    "<h2>Learning Objectives</h2>\n",
    "\n",
    "By the end of this chapter, you will be able to:\n",
    "\n",
    "1. Distinguish a figure from its axes and build single- and multi-chart figures with `plt.subplots()`.\n",
    "2. Create line, bar, scatter, histogram, and box plots that match a management question about trend, comparison, relationship, or distribution.\n",
    "3. Label and style charts with titles, axis labels, legends, colors, line styles, markers, transparency, and axis ranges.\n",
    "4. Arrange charts for comparison with subplots, shared axes, figure titles, and `add_axes()` insets.\n",
    "5. Set figure size and resolution, save figures for reports, and finish pandas plots with Matplotlib methods.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd9881c9",
   "metadata": {},
   "source": [
    "<h2>Chapter Flow</h2>\n",
    "\n",
    "```{div} chapter-flow\n",
    "6.1. {doc}`Matplotlib Basics <0601-mpl>`\n",
    "\n",
    "6.2. {doc}`Figures and Axes <0602-figures-axes>`\n",
    "\n",
    "6.3. {doc}`Styling and Plot Types <0603-controls-plot-types>`\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecaee88c",
   "metadata": {},
   "source": [
    "<h2>Glossary</h2>\n",
    "\n",
    "| # | Term | Explanation |\n",
    "|---:|---|---|\n",
    "| 1 | Matplotlib | A Python library for creating charts; pandas and Seaborn plotting are built on it. |\n",
    "| 2 | pyplot | The `matplotlib.pyplot` module, usually imported as `plt`, that provides the plotting functions. |\n",
    "| 3 | Stateful interface | A pyplot style where functions such as `plt.plot()` and `plt.title()` act on the current figure and axes. |\n",
    "| 4 | Object-oriented interface | A style that stores the figure and axes in variables and calls methods on them, such as `ax.set_title()`. |\n",
    "| 5 | Figure | The whole canvas that holds one or more axes. |\n",
    "| 6 | Axes | One chart inside a figure: the area where data, labels, and ticks are drawn. |\n",
    "| 7 | Axis | The x or y scale of an axes, with its range, ticks, and label. |\n",
    "| 8 | Tick | A marked reference value along an axis. |\n",
    "| 9 | `plt.subplot()` | A stateful function that adds one axes at a position in a grid. |\n",
    "| 10 | `plt.subplots()` | A function that creates a figure and its axes in one step and returns both. |\n",
    "| 11 | `tight_layout()` | A function that adjusts spacing so subplot titles and labels do not overlap. |\n",
    "| 12 | Figure title | One title above all subplots, set with `fig.suptitle()`. |\n",
    "| 13 | Shared axis | An axis range used by every subplot, set with `sharex=True` or `sharey=True`, so charts compare fairly. |\n",
    "| 14 | `add_axes()` | A figure method that places an axes at `[left, bottom, width, height]` in fractions of the figure. |\n",
    "| 15 | Inset axes | A small axes placed on top of a larger chart, often to zoom in on part of the data. |\n",
    "| 16 | Figure size | The width and height of a figure in inches, set with `figsize=`. |\n",
    "| 17 | DPI | Dots per inch: the resolution used to draw or save a figure. |\n",
    "| 18 | `savefig()` | A method that saves a figure to a file such as PNG, PDF, or SVG. |\n",
    "| 19 | Format string | A short code such as `'r--'` that sets color, line style, and marker in one argument. |\n",
    "| 20 | Line style | The pattern used to draw a line, such as solid, dashed, or dotted. |\n",
    "| 21 | Marker | A symbol drawn at each data point, such as a circle or square. |\n",
    "| 22 | Alpha | Transparency from 0 (invisible) to 1 (opaque), useful when marks overlap. |\n",
    "| 23 | Legend | A key that explains which color or style belongs to which series. |\n",
    "| 24 | Title | Text above an axes that names its subject or message. |\n",
    "| 25 | Axis label | Text that says what an axis measures, including units. |\n",
    "| 26 | Axis range | The lowest and highest values shown on an axis, set with `set_xlim()` and `set_ylim()`. |\n",
    "| 27 | rcParams | Matplotlib's default settings for every part of a chart (\"runtime configuration\"), loaded when Matplotlib starts and changeable while a program runs. |\n",
    "| 28 | Style sheet | A named set of appearance settings applied with `plt.style.use()`. |\n",
    "| 29 | Line plot | Points connected in order; suited to trends over time. |\n",
    "| 30 | Scatter plot | Points for pairs of numeric values; suited to relationships. |\n",
    "| 31 | Bar plot | Rectangles whose heights compare values across categories. |\n",
    "| 32 | Histogram | Bars that count how many values fall in each bin; suited to distributions. |\n",
    "| 33 | Bin | One interval of values counted in a histogram. |\n",
    "| 34 | Boxplot | A summary of a distribution showing the median, quartiles, whiskers, and outliers. |"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6ac73fd",
   "metadata": {},
   "source": [
    "<h2><a href=\"overview.html\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"color: var(--pst-color-link, #176de8);\">Chapter Overview Slides</a></h2>\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv (3.13.7)",
   "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.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
