{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import Terminus\n", "import json\n", "\n", "Terminus.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "In this notebook we're going to use Plotapi Terminus to visualise how degree classes vary by graduates' ethnicity. We\"ll use Python, but Plotapi can be used from any programming language.\n", "\n", "In the Terminus diagram (a type of flow diagram), we can watch the journey of something or someone from some starting category to some ending category. In this case, we'll be watching each unit travel from a graduate's ethnicity to their awarded degree classification." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to use data that has been published by the Higher Education Statistics Agency (HESA) in the UK. The data table is titled \"UK domiciled first degree qualifiers by classification of first degree, religious belief, sex, age group, disability marker, ethnicity marker, mode of study and academic year\" and it can be [found at this link](https://www.hesa.ac.uk/data-and-analysis/students/table-26).\n", "\n", "We will use data from all countries, all modes of study, and from the academic year 2019/20. \"Other\" and \"Not known\" have been combined.\n", "\n", "The degree class is the result achieved by a student UK, similar to a Grade Point Average (GPA). You can find a mapping between UK degree classifications and GPA [here](http://www.fulbright.org.uk/going-to-the-usa/pre-departure/academics)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "data = [\n", " {\"source\": \"White\", \"target\": \"First class\", \"value\": 92260},\n", " {\"source\": \"White\", \"target\": \"Second class (upper)\", \"value\": 114885},\n", " {\"source\": \"White\", \"target\": \"Second class (lower)\", \"value\": 29325},\n", " {\"source\": \"White\", \"target\": \"Third class\", \"value\": 4775},\n", " {\"source\": \"White\", \"target\": \"Unclassified\", \"value\": 12585},\n", " \n", " {\"source\": \"Black\", \"target\": \"First class\", \"value\": 4340},\n", " {\"source\": \"Black\", \"target\": \"Second class (upper)\", \"value\": 10640},\n", " {\"source\": \"Black\", \"target\": \"Second class (lower)\", \"value\": 6245},\n", " {\"source\": \"Black\", \"target\": \"Third class\", \"value\": 1555},\n", " {\"source\": \"Black\", \"target\": \"Unclassified\", \"value\": 750},\n", " \n", " {\"source\": \"Asian\", \"target\": \"First class\", \"value\": 11515},\n", " {\"source\": \"Asian\", \"target\": \"Second class (upper)\", \"value\": 17925},\n", " {\"source\": \"Asian\", \"target\": \"Second class (lower)\", \"value\": 7080},\n", " {\"source\": \"Asian\", \"target\": \"Third class\", \"value\": 1440},\n", " {\"source\": \"Asian\", \"target\": \"Unclassified\", \"value\": 2710},\n", " \n", " {\"source\": \"Mixed\", \"target\": \"First class\", \"value\": 4575},\n", " {\"source\": \"Mixed\", \"target\": \"Second class (upper)\", \"value\": 6740},\n", " {\"source\": \"Mixed\", \"target\": \"Second class (lower)\", \"value\": 2095},\n", " {\"source\": \"Mixed\", \"target\": \"Third class\", \"value\": 355},\n", " {\"source\": \"Mixed\", \"target\": \"Unclassified\", \"value\": 565},\n", " \n", " {\"source\": \"Other/NA\", \"target\": \"First class\", \"value\": 1415 + 1370},\n", " {\"source\": \"Other/NA\", \"target\": \"Second class (upper)\", \"value\": 2385 + 2350},\n", " {\"source\": \"Other/NA\", \"target\": \"Second class (lower)\", \"value\": 1065 + 1380},\n", " {\"source\": \"Other/NA\", \"target\": \"Third class\", \"value\": 190 + 985},\n", " {\"source\": \"Other/NA\", \"target\": \"Unclassified\", \"value\": 290 + 635}\n", "]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's use Plotapi Terminus for this visualisation, you can see more examples [in the Gallery](https://plotapi.com/gallery/).\n", "\n", "We're going to adjust some layout and template parameters. We're setting `percentage_by_source=True` to see the degree class awarded as a percentage within ethnicity, i.e. each percentage column will sum to 100. We'll also set `pixels_per_percentage=50` to control the length of the animation, making it shorter than the default of setting.
" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", " \n", " \n", " Plotapi - Terminus Diagram\n", " \n", " \n", " \n", "\n", " \n", "
\n", " \n", " \n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Terminus(data, width=1000, percentage_by_source=True, pixels_per_percentage=50,\n", " title=\"Watch graduate's collect their degree (by percentage within ethnicity)\").show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.1" } }, "nbformat": 4, "nbformat_minor": 4 }