{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# An Introduction to Visualising In the Spotlight Data Using Python\n", "\n", "In this notebook we will introduce a way of producing visualisations of [*In the Spotlight*](https://www.libcrowds.com/collection/playbills) results data, using Python.\n", "\n", "[Plotly.py](https://plot.ly/d3-js-for-python-and-pandas-charts/) is a Python graphing library that can be used to produce over 30 chart types that can viewed in Jupyter notebooks. We will use it here to produce pie and bar charts. In future notebooks we may go on to explore some more complex chart types.\n", "\n", "We begin by importing the required Python libraries, pandas and plotly." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "import pandas\n", "import plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The dataset\n", "\n", "Our input will be the dataframe of performance data introduced in a [previous notebook](intro_to_analysing_its_data_using_python.ipynb). Again, all we need to know about the code block below is that it loads our dataframe of performance data." ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import os\n", "import sys\n", "module_path = os.path.abspath(os.path.join('..', 'data', 'scripts'))\n", "if module_path not in sys.path:\n", " sys.path.append(module_path)\n", "from get_its_performances import get_performances_df\n", "df = get_performances_df()\n", "\n", "# Sets plotly to offline mode\n", "plotly.offline.init_notebook_mode()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a reminder of how this dataframe looks we can run the `head()` function." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | title | \n", "date | \n", "genre | \n", "link | \n", "theatre | \n", "city | \n", "source | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "Pageantry | \n", "NaN | \n", "NaN | \n", "http://access.bl.uk/item/viewer/ark:/81055/vdc... | \n", "Theatre Royal, Margate | \n", "Margate | \n", "https://api.bl.uk/metadata/iiif/ark:/81055/vdc... | \n", "
1 | \n", "The Hypocrite | \n", "NaN | \n", "Comedy | \n", "http://access.bl.uk/item/viewer/ark:/81055/vdc... | \n", "Theatre Royal, Margate | \n", "Margate | \n", "https://api.bl.uk/metadata/iiif/ark:/81055/vdc... | \n", "
2 | \n", "The Padlock | \n", "NaN | \n", "Musical Farce | \n", "http://access.bl.uk/item/viewer/ark:/81055/vdc... | \n", "Theatre Royal, Margate | \n", "Margate | \n", "https://api.bl.uk/metadata/iiif/ark:/81055/vdc... | \n", "
3 | \n", "The Village Lawyer | \n", "NaN | \n", "Farce | \n", "http://access.bl.uk/item/viewer/ark:/81055/vdc... | \n", "Theatre Royal, Margate | \n", "Margate | \n", "https://api.bl.uk/metadata/iiif/ark:/81055/vdc... | \n", "
4 | \n", "Death of Gen. Wolfe | \n", "NaN | \n", "Ballet | \n", "http://access.bl.uk/item/viewer/ark:/81055/vdc... | \n", "Theatre Royal, Margate | \n", "Margate | \n", "https://api.bl.uk/metadata/iiif/ark:/81055/vdc... | \n", "