{ "cells": [ { "cell_type": "markdown", "id": "355e0c61", "metadata": {}, "source": [ "# New Zealand DEM remake\n", "\n", "See the original notebook [here](https://nbviewer.org/github/royalosyin/Work-with-DEM-data-using-Python-from-Simple-to-Complicated/blob/master/Sup03-Ridgelines%20Map%20of%20DEM.ipynb)." ] }, { "cell_type": "code", "execution_count": 1, "id": "9d10728d", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:38:36.146440Z", "iopub.status.busy": "2024-04-17T07:38:36.146184Z", "iopub.status.idle": "2024-04-17T07:38:36.464439Z", "shell.execute_reply": "2024-04-17T07:38:36.464116Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "4d778c93", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:38:36.466035Z", "iopub.status.busy": "2024-04-17T07:38:36.465850Z", "iopub.status.idle": "2024-04-17T07:38:36.468086Z", "shell.execute_reply": "2024-04-17T07:38:36.467882Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "7faa0eb9", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:38:36.469253Z", "iopub.status.busy": "2024-04-17T07:38:36.469073Z", "iopub.status.idle": "2024-04-17T07:38:36.470756Z", "shell.execute_reply": "2024-04-17T07:38:36.470580Z" } }, "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", " return df" ] }, { "cell_type": "code", "execution_count": 4, "id": "439267fa", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:38:36.471732Z", "iopub.status.busy": "2024-04-17T07:38:36.471618Z", "iopub.status.idle": "2024-04-17T07:38:36.857892Z", "shell.execute_reply": "2024-04-17T07:38:36.857616Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(1095, 3)\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyh
5051052130.991302
507107219.021566
910110439.025543
91411444.319343
915115441.220718
\n", "
" ], "text/plain": [ " x y h\n", "505 105 2 130.991302\n", "507 107 2 19.021566\n", "910 110 4 39.025543\n", "914 114 4 4.319343\n", "915 115 4 41.220718" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "raw_data_array = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/new_zealand.csv\", header=None).to_numpy()\n", "df = dataset_array_to_dataframe(raw_data_array)\n", "df = df[df.h > 0]\n", "print(df.shape)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 5, "id": "4e517dcc", "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:38:36.859053Z", "iopub.status.busy": "2024-04-17T07:38:36.858979Z", "iopub.status.idle": "2024-04-17T07:38:36.894097Z", "shell.execute_reply": "2024-04-17T07:38:36.893818Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ggplot(df) + \\\n", " geom_area_ridges(aes(\"x\", \"y\", height=\"h\"), \\\n", " stat='identity', scale=.002, \\\n", " color=\"#08519c\", fill=\"#bdd7e7\",\n", " sampling=sampling_pick(df.shape[0]), \\\n", " tooltips='none') + \\\n", " geom_text(x=140, y=65, label=\"New Zealand\", size=20, family=\"Cinzel\") + \\\n", " scale_y_continuous(trans='reverse') + \\\n", " ggsize(600, 600) + \\\n", " theme_minimal() + theme(axis='blank', panel_grid='blank', \\\n", " plot_background=element_rect(color='black', fill='#e6e6e6', size=1))" ] } ], "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.13" } }, "nbformat": 4, "nbformat_minor": 5 }