{ "cells": [ { "cell_type": "markdown", "id": "e8d8eaf2", "metadata": {}, "source": [ "# A post-punk chart remake\n", "\n", "Original: https://blog.datawrapper.de/weekly-ridgeline-plot/" ] }, { "cell_type": "code", "execution_count": 1, "id": "29a1a1d1", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:17.071823Z", "iopub.status.busy": "2024-04-17T07:39:17.071735Z", "iopub.status.idle": "2024-04-17T07:39:17.394153Z", "shell.execute_reply": "2024-04-17T07:39:17.393699Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "081d0161", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:17.395752Z", "iopub.status.busy": "2024-04-17T07:39:17.395602Z", "iopub.status.idle": "2024-04-17T07:39:17.397904Z", "shell.execute_reply": "2024-04-17T07:39:17.397720Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "037078d1", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:17.398818Z", "iopub.status.busy": "2024-04-17T07:39:17.398747Z", "iopub.status.idle": "2024-04-17T07:39:17.400438Z", "shell.execute_reply": "2024-04-17T07:39:17.400258Z" } }, "outputs": [], "source": [ "def dataset_array_to_dataframe(dataset_array):\n", " df = pd.DataFrame.from_records([\n", " (j, i, a)\n", " for i, r in enumerate(dataset_array)\n", " for j, a in enumerate(r)\n", " ], columns=[\"x\", \"y\", \"h\"])\n", " df.h = df.h + abs(df.h.min())\n", " return df" ] }, { "cell_type": "code", "execution_count": 4, "id": "57c086aa", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:17.401223Z", "iopub.status.busy": "2024-04-17T07:39:17.401145Z", "iopub.status.idle": "2024-04-17T07:39:17.856803Z", "shell.execute_reply": "2024-04-17T07:39:17.856509Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(24000, 3)\n" ] }, { "data": { "text/html": [ "\n", " | x | \n", "y | \n", "h | \n", "
---|---|---|---|
0 | \n", "0 | \n", "0 | \n", "5.24 | \n", "
1 | \n", "1 | \n", "0 | \n", "5.14 | \n", "
2 | \n", "2 | \n", "0 | \n", "4.96 | \n", "
3 | \n", "3 | \n", "0 | \n", "5.05 | \n", "
4 | \n", "4 | \n", "0 | \n", "5.46 | \n", "