{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## CS 200: Matplotlib\n", "\n", "
\n",
"\n",
" \n",
"The material in this notebook comes from matplotlib.org, mainly the introductory tutorials. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Usage Guide\n",
"\n",
"This tutorial covers some basic usage patterns and best-practices to help you get started with Matplotlib."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A simple example\n",
"\n",
"Matplotlib graphs your data on Figures (i.e., windows, Jupyter widgets, etc.), each of which can contain one or more Axes (i.e., an area where points can be specified in terms of x-y coordinates (or theta-r in a polar plot, or x-y-z in a 3D plot, etc.). The most simple way of creating a figure with an axes is using pyplot.subplots
. We can then use Axes.plot
to draw some data on the axes:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"["
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Figure\n",
"\n",
"The whole figure. The figure keeps track of all the child Axes, a smattering of 'special' artists (titles, figure legends, etc), and the canvas. (Don't worry too much about the canvas, it is crucial as it is the object that actually does the drawing to get you your plot, but as the user it is more-or-less invisible to you). A figure can contain any number of Axes, but will typically have at least one.\n",
"\n",
"The easiest way to create a new figure is with pyplot:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"