{ "cells": [ { "cell_type": "markdown", "id": "vocal-mileage", "metadata": {}, "source": [ "# Interactive Data Graphics with Plotly\n", "\n", "In this lecture, we'll use the Plotly library to construct engaging interactive graphics using a high-level interface. We already worked with Plotly when we created attractive geographic data visualizations. In this lecture, we'll use Plotly to build out the rest of our standard data visualization tools. \n", "\n", "There are a number of plot types not shown here: check the [Plotly Express overview](https://plotly.com/python/plotly-express/) for many other interesting and useful plot types. \n", "\n", "For this lecture, we're going to take a break from the NOAA climate data set. You'll use Plotly to construct visualizations using this data in HW1. For now, we're going to use the #BestDataSet: Palmer Penguins! \n", "\n", "\n", "\n", "First, let's retrieve and clean up the data a little. These are all standard pandas operations, so we're not going to spend much time here. " ] }, { "cell_type": "code", "execution_count": 2, "id": "developing-active", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "url = \"https://raw.githubusercontent.com/PhilChodrow/PIC16B/master/datasets/palmer_penguins.csv\"\n", "penguins = pd.read_csv(url)\n", "penguins = penguins.dropna(subset = [\"Body Mass (g)\", \"Sex\"])\n", "penguins[\"Species\"] = penguins[\"Species\"].str.split().str.get(0)\n", "penguins = penguins[penguins[\"Sex\"] != \".\"]\n", "\n", "cols = [\"Species\", \"Island\", \"Sex\", \"Culmen Length (mm)\", \"Culmen Depth (mm)\", \"Flipper Length (mm)\", \"Body Mass (g)\"]\n", "penguins = penguins[cols]" ] }, { "cell_type": "markdown", "id": "running-technique", "metadata": {}, "source": [ "Let's take a look at the simplified data set: " ] }, { "cell_type": "code", "execution_count": 3, "id": "verified-foundation", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Species | \n", "Island | \n", "Sex | \n", "Culmen Length (mm) | \n", "Culmen Depth (mm) | \n", "Flipper Length (mm) | \n", "Body Mass (g) | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "Adelie | \n", "Torgersen | \n", "MALE | \n", "39.1 | \n", "18.7 | \n", "181.0 | \n", "3750.0 | \n", "
1 | \n", "Adelie | \n", "Torgersen | \n", "FEMALE | \n", "39.5 | \n", "17.4 | \n", "186.0 | \n", "3800.0 | \n", "
2 | \n", "Adelie | \n", "Torgersen | \n", "FEMALE | \n", "40.3 | \n", "18.0 | \n", "195.0 | \n", "3250.0 | \n", "
4 | \n", "Adelie | \n", "Torgersen | \n", "FEMALE | \n", "36.7 | \n", "19.3 | \n", "193.0 | \n", "3450.0 | \n", "
5 | \n", "Adelie | \n", "Torgersen | \n", "MALE | \n", "39.3 | \n", "20.6 | \n", "190.0 | \n", "3650.0 | \n", "