diff --git a/docs/maplibre/housing_prices.ipynb b/docs/maplibre/housing_prices.ipynb new file mode 100644 index 0000000000..d6924d9728 --- /dev/null +++ b/docs/maplibre/housing_prices.ipynb @@ -0,0 +1,177 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0", + "metadata": {}, + "source": [ + "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=maplibre/housing_prices.ipynb)\n", + "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/maplibre/housing_prices.ipynb)\n", + "[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n", + "\n", + "**Mapping US Housing Prices by County**\n", + "\n", + "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1", + "metadata": {}, + "outputs": [], + "source": [ + "# %pip install \"leafmap[maplibre]\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2", + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import leafmap.maplibregl as leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3", + "metadata": {}, + "outputs": [], + "source": [ + "geojson = \"https://github.com/opengeos/datasets/releases/download/us/zillow_home_value_by_county.geojson\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4", + "metadata": {}, + "outputs": [], + "source": [ + "gdf = gpd.read_file(geojson)\n", + "gdf.head()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5", + "metadata": {}, + "outputs": [], + "source": [ + "column = \"2024-10-31\"\n", + "data = gdf[[\"RegionName\", \"State\", column, \"geometry\"]]\n", + "data.head()" + ] + }, + { + "cell_type": "markdown", + "id": "6", + "metadata": {}, + "source": [ + "Available classification schemes: \n", + "* BoxPlot\n", + "* EqualInterval\n", + "* FisherJenks\n", + "* FisherJenksSampled\n", + "* HeadTailBreaks\n", + "* JenksCaspall\n", + "* JenksCaspallForced\n", + "* JenksCaspallSampled\n", + "* MaxP\n", + "* MaximumBreaks\n", + "* NaturalBreaks\n", + "* Quantiles\n", + "* Percentiles\n", + "* StdMean\n", + "* UserDefined" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7", + "metadata": {}, + "outputs": [], + "source": [ + "m = leafmap.Map(style=\"liberty\", pitch=60)\n", + "first_symbol_id = m.find_first_symbol_layer()[\"id\"]\n", + "m.add_data(\n", + " data,\n", + " column=column,\n", + " scheme=\"Quantiles\",\n", + " cmap=\"Blues\",\n", + " legend_title=\"Median Home Value\",\n", + " name=\"Home value\",\n", + " before_id=first_symbol_id,\n", + " extrude=True,\n", + " scale_factor=3,\n", + ")\n", + "m.add_layer_control()\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "8", + "metadata": {}, + "source": [ + "![image](https://github.com/user-attachments/assets/9052e391-a26a-4a75-9ffe-d4abac3c0fce)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9", + "metadata": {}, + "outputs": [], + "source": [ + "m = leafmap.Map(style=\"liberty\")\n", + "m.add_data(\n", + " data,\n", + " column=column,\n", + " scheme=\"Quantiles\",\n", + " cmap=\"Blues\",\n", + " legend_title=\"Median Home Value\",\n", + " name=\"Home value\",\n", + " before_id=first_symbol_id,\n", + ")\n", + "m.add_layer_control()\n", + "m" + ] + }, + { + "cell_type": "markdown", + "id": "10", + "metadata": {}, + "source": [ + "![image](https://github.com/user-attachments/assets/b44338cf-0e5a-420b-b7c0-ff9fa6896943)" + ] + } + ], + "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.11.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/maplibre/overview.md b/docs/maplibre/overview.md index 387f3209c2..763cfe7507 100644 --- a/docs/maplibre/overview.md +++ b/docs/maplibre/overview.md @@ -339,6 +339,12 @@ Visualize earthquake frequency by location using a heatmap layer. [![](https://i.imgur.com/OLCRPKj.png)](https://leafmap.org/maplibre/heatmap_layer) +## Visualize US median housing prices by county + +Visualize US median housing prices by county using a choropleth map. + +[![](https://github.com/user-attachments/assets/9052e391-a26a-4a75-9ffe-d4abac3c0fce)](https://leafmap.org/maplibre/housing_prices) + ## Display a non-interactive map Disable interactivity to create a static map. diff --git a/mkdocs.yml b/mkdocs.yml index 0569ac01fb..a8b065229d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -200,6 +200,7 @@ nav: - maplibre/google_earth_engine.ipynb - maplibre/gps_trace.ipynb - maplibre/heatmap_layer.ipynb + - maplibre/housing_prices.ipynb - maplibre/interactive_false.ipynb - maplibre/jump_to.ipynb - maplibre/language_switch.ipynb