{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preamble" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from plotapi import Chord\n", "import json\n", "\n", "Chord.set_license(\"your username\", \"your license key\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction\n", "\n", "In this notebook we're going to use Plotapi Chord to visualise the co-occurrences of genres in the IMDb \"Top 1000\" (Sorted by IMDb Rating Descending). We\"ll use Python, but Plotapi can be used from any programming language.\n", "\n", "In a chord diagram (or radial network), entities are arranged radially as segments with their relationships visualised by ribbons that connect them. The size of the segments illustrates the numerical proportions, whilst the size of the arc illustrates the significance of the relationships. Chord diagrams are useful when trying to convey relationships between different entities, and they can be beautiful and eye-catching." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Dataset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We're going to use the latest IMDB top 1000 data which is available on [their website](https://www.imdb.com/search/title/?count=50&groups=top_1000&sort=user_rating). Let\"s get loading the data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "with open(\"imdb_top_1000.json\", \"r\") as f:\n", " data = json.load(f)\n", " \n", "names = ['Action', 'Adventure', 'Animation', 'Biography', 'Comedy',\n", " 'Crime', 'Drama', 'Family', 'Fantasy', 'Film-Noir',\n", " 'History', 'Horror', 'Music', 'Musical', 'Mystery',\n", " 'Romance', 'Sci-Fi', 'Sport', 'Thriller', 'War', 'Western']" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualisation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's use Plotapi Chord 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, and flip the intro animation on too. We'll also configure the data table to hide the indices, and we'll make sure to compress our data table so we have a smaller output size. Finally, we've also set `data_table_unique_column=\"Name\"`, because we have instances where a title has 3 or more genres, and we don't want them to appear multiple times in the same data table selection.\n", "\n", "Because we're using a data-table, we can also click on any part of the diagram to \"lock\" the selection.
" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "Plotapi - Chord Diagram\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", " \n", " \n", " \n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Chord(\n", " data[\"matrix\"],\n", " names,\n", " colors=\"movies\",\n", " noun=\"titles\",\n", " data_table_column_width=100,\n", " data_table_unique_column=\"Name\",\n", " data_table_show_indices=False,\n", " compress=True,\n", " data_table=data[\"data_table\"],\n", " animated_intro=True\n", ").show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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 }