{ "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 between the _species_ and _personality_ of Animal Crossing villagers. 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 data from Animal Crossing New Horizons data. Previously, we made use of the data available in this [repository](https://www.kaggle.com/jessicali9530/animal-crossing-new-horizons-nookplaza-dataset). However, since the 2.0 update, we've created our own! Let's get loading the data." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "with open(\"ac_species_personality.json\", \"r\") as f:\n", " data = json.load(f)" ] }, { "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.\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": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "code", "execution_count": 3, "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", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Chord(\n", " data[\"matrix\"],\n", " data[\"names\"],\n", " colors=data[\"colors\"],\n", " details=data[\"details\"],\n", " details_thumbs=data[\"details_thumbs\"],\n", " noun=\"villagers!\",\n", " thumbs_width=50,\n", " curved_labels=True,\n", " popup_width=600,\n", " bipartite=True,\n", " bipartite_idx=data[\"bipartite_idx\"],\n", " bipartite_size=0.4,\n", " padding=0.0,\n", " width=800,\n", " data_table_column_width=100,\n", " font_size_large=\"16px\",\n", " data_table=data[\"data_table\"],\n", " data_table_show_indices=False\n", ").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.10.4" } }, "nbformat": 4, "nbformat_minor": 4 }