{ "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": "2025-11-05T13:55:32.615114Z", "iopub.status.busy": "2025-11-05T13:55:32.614997Z", "iopub.status.idle": "2025-11-05T13:55:32.618307Z", "shell.execute_reply": "2025-11-05T13:55:32.618061Z" } }, "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": "2025-11-05T13:55:32.619197Z", "iopub.status.busy": "2025-11-05T13:55:32.619131Z", "iopub.status.idle": "2025-11-05T13:55:32.621000Z", "shell.execute_reply": "2025-11-05T13:55:32.620774Z" } }, "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": "2025-11-05T13:55:32.621733Z", "iopub.status.busy": "2025-11-05T13:55:32.621668Z", "iopub.status.idle": "2025-11-05T13:55:32.623391Z", "shell.execute_reply": "2025-11-05T13:55:32.623151Z" } }, "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": "2025-11-05T13:55:32.624075Z", "iopub.status.busy": "2025-11-05T13:55:32.624006Z", "iopub.status.idle": "2025-11-05T13:55:33.050836Z", "shell.execute_reply": "2025-11-05T13:55:33.050500Z" } }, "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", "