{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Matplotlib\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Matplotlib\n", "\n", "Matplotlib is a package for creating data visualizations. It provides tools for creating a wide range of plots, and allows for a high level of customization. \n", "\n", "Python has two distint interfaces than can be used to generate plots. We will primarily by working with the `pyplot` API (Application Programming Interface). By convention, this is typically imported under the alias `plt`, as in the cell below." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import Gapminder Data \n", "\n", "For some of the examples in this lesson, we will be working with the gapminder dataset. This dataset contains socioeconomic data for 184 countries over a period of 219 years, from 1800 to 2018. The data you will be working with is contained in the file `gapminder_data.txt`. Please download this file into the same folder that contains this notebook. \n", "\n", "In the cell below, we use a package called Pandas to import the data. The data is stored in a pandas data type called a `DataFrame`. DataFrames are used to contain tabular data arranged in rows and columns. \n", "\n", "After importinng the data, we select only the records from 2018. Then to get a sense as to what this dataset looks like, we display the first 10 rows of the filtered dataframe. Don't worry about figuring out how this code works just yet. We will cover pandas in detail in a later lesson. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | country | \n", "year | \n", "continent | \n", "population | \n", "life_exp | \n", "gdp_per_cap | \n", "gini | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "Afghanistan | \n", "2018 | \n", "asia | \n", "36400000 | \n", "58.7 | \n", "1870 | \n", "36.8 | \n", "
1 | \n", "Albania | \n", "2018 | \n", "europe | \n", "2930000 | \n", "78.0 | \n", "12400 | \n", "29.0 | \n", "
2 | \n", "Algeria | \n", "2018 | \n", "africa | \n", "42000000 | \n", "77.9 | \n", "13700 | \n", "27.6 | \n", "
3 | \n", "Angola | \n", "2018 | \n", "africa | \n", "30800000 | \n", "65.2 | \n", "5850 | \n", "42.6 | \n", "
4 | \n", "Antigua and Barbuda | \n", "2018 | \n", "americas | \n", "103000 | \n", "77.6 | \n", "21000 | \n", "40.0 | \n", "
5 | \n", "Argentina | \n", "2018 | \n", "americas | \n", "44700000 | \n", "77.0 | \n", "18900 | \n", "42.4 | \n", "
6 | \n", "Armenia | \n", "2018 | \n", "europe | \n", "2930000 | \n", "76.0 | \n", "8660 | \n", "32.6 | \n", "
7 | \n", "Australia | \n", "2018 | \n", "asia | \n", "24800000 | \n", "82.9 | \n", "45800 | \n", "32.3 | \n", "
8 | \n", "Austria | \n", "2018 | \n", "europe | \n", "8750000 | \n", "81.8 | \n", "44600 | \n", "30.5 | \n", "
9 | \n", "Azerbaijan | \n", "2018 | \n", "europe | \n", "9920000 | \n", "72.3 | \n", "16600 | \n", "32.4 | \n", "