{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Visualizing Two Quantitative Variables\n", "> In this chapter, you will create and customize plots that visualize the relationship between two quantitative variables. To do this, you will use scatter plots and line plots to explore how the level of air pollution in a city changes over the course of a day and how horsepower relates to fuel efficiency in cars. You will also see another big advantage of using Seaborn - the ability to easily create subplots in a single figure! This is the Summary of lecture \"Introduction to Data Visualization with Seaborn\", via datacamp.\n", "\n", "- toc: true \n", "- badges: true\n", "- comments: true\n", "- author: Chanseok Kang\n", "- categories: [Python, Datacamp, Visualization]\n", "- image: images/mpg_origin.png" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "plt.rcParams['figure.figsize'] = (10, 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction to relational plots and subplots\n", "- Relational plots\n", " - Height vs. Weight\n", " - Number of school absences vs. final grade\n", " - GDP vs. percentile literate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Creating subplots with col and row\n", "We've seen in prior exercises that students with more absences (`\"absences\"`) tend to have lower final grades (`\"G3\"`). Does this relationship hold regardless of how much time students study each week?\n", "\n", "To answer this, we'll look at the relationship between the number of absences that a student has in school and their final grade in the course, creating separate subplots based on each student's weekly study time (`\"study_time\"`)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | school | \n", "sex | \n", "age | \n", "famsize | \n", "Pstatus | \n", "Medu | \n", "Fedu | \n", "traveltime | \n", "failures | \n", "schoolsup | \n", "... | \n", "goout | \n", "Dalc | \n", "Walc | \n", "health | \n", "absences | \n", "G1 | \n", "G2 | \n", "G3 | \n", "location | \n", "study_time | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "GP | \n", "F | \n", "18 | \n", "GT3 | \n", "A | \n", "4 | \n", "4 | \n", "2 | \n", "0 | \n", "yes | \n", "... | \n", "4 | \n", "1 | \n", "1 | \n", "3 | \n", "6 | \n", "5 | \n", "6 | \n", "6 | \n", "Urban | \n", "2 to 5 hours | \n", "
1 | \n", "GP | \n", "F | \n", "17 | \n", "GT3 | \n", "T | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "3 | \n", "1 | \n", "1 | \n", "3 | \n", "4 | \n", "5 | \n", "5 | \n", "6 | \n", "Urban | \n", "2 to 5 hours | \n", "
2 | \n", "GP | \n", "F | \n", "15 | \n", "LE3 | \n", "T | \n", "1 | \n", "1 | \n", "1 | \n", "3 | \n", "yes | \n", "... | \n", "2 | \n", "2 | \n", "3 | \n", "3 | \n", "10 | \n", "7 | \n", "8 | \n", "10 | \n", "Urban | \n", "2 to 5 hours | \n", "
3 | \n", "GP | \n", "F | \n", "15 | \n", "GT3 | \n", "T | \n", "4 | \n", "2 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "2 | \n", "1 | \n", "1 | \n", "5 | \n", "2 | \n", "15 | \n", "14 | \n", "15 | \n", "Urban | \n", "5 to 10 hours | \n", "
4 | \n", "GP | \n", "F | \n", "16 | \n", "GT3 | \n", "T | \n", "3 | \n", "3 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "2 | \n", "1 | \n", "2 | \n", "5 | \n", "4 | \n", "6 | \n", "10 | \n", "10 | \n", "Urban | \n", "2 to 5 hours | \n", "
5 rows × 29 columns
\n", "\n", " | mpg | \n", "cylinders | \n", "displacement | \n", "horsepower | \n", "weight | \n", "acceleration | \n", "model_year | \n", "origin | \n", "name | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "18.0 | \n", "8 | \n", "307.0 | \n", "130.0 | \n", "3504 | \n", "12.0 | \n", "70 | \n", "usa | \n", "chevrolet chevelle malibu | \n", "
1 | \n", "15.0 | \n", "8 | \n", "350.0 | \n", "165.0 | \n", "3693 | \n", "11.5 | \n", "70 | \n", "usa | \n", "buick skylark 320 | \n", "
2 | \n", "18.0 | \n", "8 | \n", "318.0 | \n", "150.0 | \n", "3436 | \n", "11.0 | \n", "70 | \n", "usa | \n", "plymouth satellite | \n", "
3 | \n", "16.0 | \n", "8 | \n", "304.0 | \n", "150.0 | \n", "3433 | \n", "12.0 | \n", "70 | \n", "usa | \n", "amc rebel sst | \n", "
4 | \n", "17.0 | \n", "8 | \n", "302.0 | \n", "140.0 | \n", "3449 | \n", "10.5 | \n", "70 | \n", "usa | \n", "ford torino | \n", "