{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "**Tools - matplotlib**\n", "\n", "*This notebook demonstrates how to use the matplotlib library to plot beautiful graphs.*" ] }, { "cell_type": "markdown", "metadata": { "toc": "true" }, "source": [ "# Table of Contents\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plotting your first graph" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First let's make sure that this notebook works well in both python 2 and 3:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from __future__ import division, print_function, unicode_literals", ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we need to import the `matplotlib` library." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import matplotlib" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Matplotlib can output graphs using various backend graphics libraries, such as Tk, wxPython, etc. When running python using the command line, the graphs are typically shown in a separate window. In a Jupyter notebook, we can simply output the graphs within the notebook itself by running the `%matplotlib inline` magic command." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "# matplotlib.use(\"TKAgg\") # use this instead in your program if you want to use Tk as your graphics backend." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's plot our first graph! :)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWoAAAEACAYAAACatzzfAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAGMZJREFUeJzt3X+Q1PV9x/HnG6EZSDCjaRraGGgvwETbkAiYYK5pF0iN\nkUS0dISJobFXMqkxNZMfiMVYsIOkkba2RQJTCFYrKkmxI0ommGnYGGjBi5wlKg4gLU2bkmk8B4ne\npMfx7h+fQ/C8Y797+939fH+8HjM3t3f33d337CxvPvt5fT+fr7k7IiKSXSNiFyAiImenRi0i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