init
This commit is contained in:
commit
8449f13314
1 file changed
+374
@@ -0,0 +1,374 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "ca04f457-164b-447a-8a7e-7864892c221b",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"jupyter": {
|
||||
"outputs_hidden": true
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Requirement already satisfied: geopy in /home/arfox/.local/lib/python3.12/site-packages (2.4.1)\n",
|
||||
"Requirement already satisfied: geographiclib<3,>=1.52 in /home/arfox/.local/lib/python3.12/site-packages (from geopy) (2.1)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n",
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Requirement already satisfied: coloraide in /home/arfox/.local/lib/python3.12/site-packages (6.2)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n",
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Requirement already satisfied: matplotlib in /home/arfox/.local/lib/python3.12/site-packages (3.8.4)\n",
|
||||
"Requirement already satisfied: contourpy>=1.0.1 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (1.3.1)\n",
|
||||
"Requirement already satisfied: cycler>=0.10 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (0.12.1)\n",
|
||||
"Requirement already satisfied: fonttools>=4.22.0 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (4.56.0)\n",
|
||||
"Requirement already satisfied: kiwisolver>=1.3.1 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (1.4.8)\n",
|
||||
"Requirement already satisfied: numpy>=1.21 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (1.26.4)\n",
|
||||
"Requirement already satisfied: packaging>=20.0 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (23.2)\n",
|
||||
"Requirement already satisfied: pillow>=8 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (11.1.0)\n",
|
||||
"Requirement already satisfied: pyparsing>=2.3.1 in /home/arfox/.local/lib/python3.12/site-packages (from matplotlib) (3.2.1)\n",
|
||||
"Requirement already satisfied: python-dateutil>=2.7 in /opt/miniconda3/envs/jupyter/lib/python3.12/site-packages (from matplotlib) (2.9.0.post0)\n",
|
||||
"Requirement already satisfied: six>=1.5 in /opt/miniconda3/envs/jupyter/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib) (1.17.0)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n",
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Requirement already satisfied: requests in /home/arfox/.local/lib/python3.12/site-packages (2.32.3)\n",
|
||||
"Requirement already satisfied: charset-normalizer<4,>=2 in /home/arfox/.local/lib/python3.12/site-packages (from requests) (3.4.1)\n",
|
||||
"Requirement already satisfied: idna<4,>=2.5 in /home/arfox/.local/lib/python3.12/site-packages (from requests) (3.10)\n",
|
||||
"Requirement already satisfied: urllib3<3,>=1.21.1 in /home/arfox/.local/lib/python3.12/site-packages (from requests) (2.4.0)\n",
|
||||
"Requirement already satisfied: certifi>=2017.4.17 in /home/arfox/.local/lib/python3.12/site-packages (from requests) (2025.1.31)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n",
|
||||
"Defaulting to user installation because normal site-packages is not writeable\n",
|
||||
"Requirement already satisfied: scipy in /home/arfox/.local/lib/python3.12/site-packages (1.15.2)\n",
|
||||
"Requirement already satisfied: numpy<2.5,>=1.23.5 in /home/arfox/.local/lib/python3.12/site-packages (from scipy) (1.26.4)\n",
|
||||
"Note: you may need to restart the kernel to use updated packages.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%pip install geopy\n",
|
||||
"%pip install coloraide\n",
|
||||
"%pip install matplotlib\n",
|
||||
"%pip install requests\n",
|
||||
"%pip install scipy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "839b8a06-f643-4896-b9db-5640d83d5511",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"from IPython.display import JSON, display, HTML\n",
|
||||
"from datetime import datetime\n",
|
||||
"from dataclasses import dataclass\n",
|
||||
"from geopy.geocoders import Nominatim\n",
|
||||
"from coloraide import Color\n",
|
||||
"from scipy import stats\n",
|
||||
"from collections import OrderedDict\n",
|
||||
"import requests\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"import numpy as np"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "b47d4ce9-0bfe-4db1-b5f0-a033034f70c2",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"I self host [Nominatim](https://nominatim.org/) with New York State loaded, it took forever to load. If you want to self host, I'd recommend you get the NYC and surrounding area from Interline: https://app.interline.io/osm_extracts/interactive_view\n",
|
||||
"\n",
|
||||
"If I remember correctly, the default Nominatim configuration connects to a free public server that requests you stay under one geocoding request per second."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "7b42f081-fac6-48f9-9c87-6b4782ebe15b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# geolocator = Nominatim(\n",
|
||||
"# domain=\"192.168.68.131:8088\",\n",
|
||||
"# scheme=\"http\",\n",
|
||||
"# user_agent=\"apt-hunt-2026\",\n",
|
||||
"# timeout=5 # My instance of Nominatim is slow and the default timeout is only one second\n",
|
||||
"# )\n",
|
||||
"\n",
|
||||
"# user_agent can basically be anything, but if you remove it it'll yell at you to pick something to identify yourself\n",
|
||||
"geolocator = Nominatim(\n",
|
||||
" user_agent=\"apt-hunt-2026\",\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "3880b549-c73c-4aa1-8524-02ef67fa2a7a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"I'm guessing you might know this part better than me, the routing library uses GraphQL and I only have a cursory understanding of it and haven't learned how to use any of the libraries like [Strawberry](https://strawberry.rocks/). I'm also not positive I have all the right modes of transit listed in this query yet."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"id": "406fe6a5-c933-4324-a2e7-a176a0dfdb11",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def build_query(origin_lat: float, origin_lon: float,\n",
|
||||
" dest_lat: float, dest_lon: float,\n",
|
||||
" earliest_departure: str = \"2026-01-05T9:30-05:00\") -> str:\n",
|
||||
" query_template = f\"\"\"\n",
|
||||
"query {{\n",
|
||||
" planConnection(\n",
|
||||
" origin: {{\n",
|
||||
" location: {{ coordinate: {{ latitude: {origin_lat}, longitude: {origin_lon} }} }}\n",
|
||||
" }}\n",
|
||||
" destination: {{\n",
|
||||
" location: {{ coordinate: {{ latitude: {dest_lat}, longitude: {dest_lon} }} }}\n",
|
||||
" }}\n",
|
||||
" dateTime: {{ earliestDeparture: \"{earliest_departure}\" }}\n",
|
||||
" modes: {{\n",
|
||||
" direct: [WALK]\n",
|
||||
" transit: {{ transit: [{{ mode: BUS }}, {{ mode: RAIL }}, {{ mode: SUBWAY }}] }}\n",
|
||||
" }}\n",
|
||||
" ) {{\n",
|
||||
" edges {{\n",
|
||||
" node {{\n",
|
||||
" start\n",
|
||||
" end\n",
|
||||
" legs {{\n",
|
||||
" mode\n",
|
||||
" from {{\n",
|
||||
" name\n",
|
||||
" lat\n",
|
||||
" lon\n",
|
||||
" departure {{\n",
|
||||
" scheduledTime\n",
|
||||
" estimated {{\n",
|
||||
" time\n",
|
||||
" delay\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" to {{\n",
|
||||
" name\n",
|
||||
" lat\n",
|
||||
" lon\n",
|
||||
" arrival {{\n",
|
||||
" scheduledTime\n",
|
||||
" estimated {{\n",
|
||||
" time\n",
|
||||
" delay\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" route {{\n",
|
||||
" gtfsId\n",
|
||||
" longName\n",
|
||||
" shortName\n",
|
||||
" }}\n",
|
||||
" legGeometry {{\n",
|
||||
" points\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
" }}\n",
|
||||
"}}\n",
|
||||
"\"\"\"\n",
|
||||
" \n",
|
||||
" return query_template.strip()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "35c24bc5-fd6d-49ce-a835-2c3b0285c617",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"I self host [OpenTripPlanner](https://docs.opentripplanner.org/en/latest/), I'm not sure if there are any easy public instances like Nominatim has. I can set up some auth for mine if you want to connect to it, right now it's only available on my home network. And it looks like PATH might be a bit more of a pain than the other transit networks, hopefully I'll have that one figured out soon."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "6e8d4cb0-735f-41b7-a765-26ce9dc56acd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def execute_plan_query(from_addr, to_addr):\n",
|
||||
" url = \"http://192.168.68.138:8080/otp/gtfs/v1\"\n",
|
||||
" headers = {\"Content-Type\": \"application/json\"}\n",
|
||||
" \n",
|
||||
" query = build_query(\n",
|
||||
" origin_lat=from_addr.latitude,\n",
|
||||
" origin_lon=from_addr.longitude,\n",
|
||||
" dest_lat=to_addr.latitude,\n",
|
||||
" dest_lon=to_addr.longitude,\n",
|
||||
" earliest_departure=\"2026-01-012T15:30-05:00\"\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
" response = requests.post(\n",
|
||||
" url,\n",
|
||||
" json={\"query\": query},\n",
|
||||
" headers=headers\n",
|
||||
" )\n",
|
||||
" \n",
|
||||
" return response.json()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "42e41f8e-8692-4b95-a4cd-242074a1ec30",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"query = {\n",
|
||||
" \"street\": \"330 34th Street\",\n",
|
||||
" \"city\": \"NEW YORK\",\n",
|
||||
" \"county\": \"New York\",\n",
|
||||
" \"state\": \"NY\",\n",
|
||||
" \"postalcode\": \"10001\",\n",
|
||||
"}\n",
|
||||
"jfk36 = geolocator.geocode(query, timeout=5)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 93,
|
||||
"id": "a7d72437-cb11-47db-b5d8-c6971836a8cd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"destinations = OrderedDict([\n",
|
||||
" (\"JFK36\", jfk36),\n",
|
||||
"])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 94,
|
||||
"id": "00fed8bd-25cc-44d8-ab39-56a8e3425a5b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"query = {\n",
|
||||
" \"street\": \"373 Washington Ave\",\n",
|
||||
" \"city\": \"NEW YORK\",\n",
|
||||
" \"county\": \"Brooklyn\",\n",
|
||||
" \"state\": \"NY\",\n",
|
||||
" \"postalcode\": \"11238\",\n",
|
||||
"}\n",
|
||||
"home = geolocator.geocode(query)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 95,
|
||||
"id": "b1fb109b-d7be-4566-994c-74805ff66e4a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"all_trips = {}\n",
|
||||
"\n",
|
||||
"all_starts = {\n",
|
||||
" \"Home\": home,\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"for label, start_loc in all_starts.items():\n",
|
||||
" all_trips[label] = []\n",
|
||||
" \n",
|
||||
" for _, dest in destinations.items():\n",
|
||||
" trips = execute_plan_query(start_loc, dest)['data']['planConnection']['edges']\n",
|
||||
" \n",
|
||||
" trip_durations = [\n",
|
||||
" (datetime.fromisoformat(trip['node']['end']) - datetime.fromisoformat(trip['node']['start']))\n",
|
||||
" for trip in trips\n",
|
||||
" ]\n",
|
||||
" trips_in_seconds = [trip.seconds for trip in trip_durations]\n",
|
||||
" trips_in_minutes = [seconds / 60 for seconds in trips_in_seconds]\n",
|
||||
" all_trips[label].append(trips_in_minutes)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 96,
|
||||
"id": "858ed8a1-5727-4b2c-a482-57733a6eafdc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"image/png": "iVBORw0KGgoAAAANSUhEUgAABdEAAAEiCAYAAAAWHJuuAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjMsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvZiW1igAAAAlwSFlzAAAPYQAAD2EBqD+naQAAN6tJREFUeJzt3Xm4VmW9P/73HmADMqqMyqCMMipahlqJkojKVyyHlHJKj6dwANRfUjmQJdZRK9MvDqV0KrX0q+nxiGYqdCxMQPGIOWEOHEVRExCHDez9/P7w8jnu4FE37M120+t1Xeu61nOve631eR65W+e8ublXWaFQKAQAAAAAAFhPeVMXAAAAAAAAn1RCdAAAAAAAKEGIDgAAAAAAJQjRAQAAAACgBCE6AAAAAACUIEQHAAAAAIAShOgAAAAAAFCCEB0AAAAAAEoQogMAAAAAQAlCdAAAAAAAKEGIDgAADWTWrFkpKyvLggULNnh87733ztChQzdzVQAAwKYQogMAAAAAQAlCdAAAAAAAKEGIDgAATWTdunU5//zz07dv31RVVaVPnz751re+lerq6jr9+vTpk4MOOihz5szJbrvtltatW2fYsGGZM2dOkuTmm2/OsGHD0qpVq+y66655+OGH17vXE088kUMPPTRbb711WrVqld122y233Xbb5viaAADQrAnRAQCgga1cuTKvvfbaetvatWvr9DvhhBNyzjnnZOTIkfnRj36Uz3/+85kxY0a+/OUvr3fNJUuW5Kijjsr48eMzY8aMvPHGGxk/fnx+/etfZ8qUKfnKV76S6dOn55lnnsnhhx+e2tra4rmPPfZYPvOZz+Txxx/PWWedlYsvvjhbbbVVJkyYkFtuuaXRfw8AAGjOygqFQqGpiwAAgC3BrFmzctxxx31onyFDhmTx4sV55JFHsvPOO+eEE07I1VdfXTx+5pln5qKLLsq9996b0aNHJ3lvJvrzzz+fP//5zxk1alSS5Pe//33Gjh2b1q1b54knnkivXr2SJFdddVVOOumk3Hfffdl7772TJGPGjMny5cszf/78VFVVJUkKhUL22muvvPrqq3nqqaca+qcAAIAthpnoAADQwC6//PLcfffd623Dhw8v9rnjjjuSJFOnTq1z7umnn54k+c///M867YMHDy4G6Emy++67J0n22WefYoD+wfa//e1vSZK///3vuffee3P44YfnzTffLM6Kf/311zN27Ng8/fTTefHFFxvqqwMAwBansqkLAACALc2nP/3p7Lbbbuu1d+rUKa+99lqS5Pnnn095eXn69etXp0+3bt3SsWPHPP/883XaPxiUJ0mHDh2SJD179txg+xtvvJHkvWVgCoVCzj777Jx99tkbrHf58uXZbrvtPu7XAwCAfypCdAAAaEJlZWUfq19FRUW92t9ftfH9tdHPOOOMjB07doN9/zHIBwAA/pcQHQAAmkDv3r1TW1ubp59+OjvttFOx/ZVXXsmKFSvSu3fvBrnPjjvumCRp0aJFxowZ0yDXBACAfybWRAcAgCZwwAEHJEl+/OMf12m/5JJLkiQHHnhgg9ynS5cu2XvvvXPllVdm2bJl6x1/9dVXG+Q+AACwpTITHQAAmsCIESNyzDHH5KqrrsqKFSvy+c9/Pg8++GB+8YtfZMKECRk9enSD3evyyy/PXnvtlWHDhuXEE0/MjjvumFdeeSXz5s3L//zP/+SRRx5psHsBAMCWRogOAABN5Gc/+1l23HHHzJo1K7fccku6deuWadOm5dxzz23Q+wwePDgLFizI9OnTM2vWrLz++uvp0qVLdtlll5xzzjkNei8AANjSlBXef+MQAAAAAABQhzXRAQAAAACgBCE6AAAAAACUIEQHAAAAAIAShOgAAAAAAFCCEB0AAAAAAEoQogMAAAAAQAmVm/uGtbW1eemll9KuXbuUlZVt7tsDAAAAALCFKxQKefPNN9OjR4+Ul2/aXPLNHqK/9NJL6dmz5+a+LQAAAAAA/2SWLl2a7bfffpOusdlD9Hbt2iV5r/j27dtv7tsDsAWqrlmTMx+9PEnyb8MmpaqiZRNXBAAAADSlVatWpWfPnsU8elNs9hD9/SVc2rdvL0QHoEFU16xJy7atkrz3fBGiAwAAAEkaZElxLxYFAAAAAIAShOgAAAAAAFCCEB0AAAAAAEqo95roL774Yr75zW9m9uzZefvtt9OvX79ce+212W233RqjPgD4SC3KK3N6/yOL+wAAAGy6mpqarF27tqnLgA1q0aJFKioqNsu96pU0vPHGG9lzzz0zevTozJ49O507d87TTz+dTp06NVZ9APCRysvKM7Bdr6YuAwAAYItQKBTy8ssvZ8WKFU1dCnyojh07plu3bg3y8tAPU68Q/Qc/+EF69uyZa6+9tti2ww47NHhRAAAAAEDTeD9A79KlS9q0adPoASXUV6FQyNtvv53ly5cnSbp3796o96tXiH7bbbdl7NixOeywwzJ37txst912+cY3vpETTzyx5DnV1dWprq4ufl61atXGVwsAG7CuUJP/eu2RJMlntx2RyrLN88+5AAAAtjQ1NTXFAH2bbbZp6nKgpNatWydJli9fni5dujTq0i71erHo3/72t8ycOTP9+/fPXXfdla9//es59dRT84tf/KLkOTNmzEiHDh2KW8+ePTe5aAC2fJctuam4fZSa2ppcv/TuXL/07tTU1myG6gAAALZM76+B3qZNmyauBD7a+39OG3vt/nqF6LW1tRk5cmQuuOCC7LLLLvmXf/mXnHjiibniiitKnjNt2rSsXLmyuC1dunSTiwYAAAAAGo8lXGgONtef03qF6N27d8/gwYPrtO2000554YUXSp5TVVWV9u3b19kAAAAAAKA5qFeIvueee+bJJ5+s0/bUU0+ld+/eDVoUAAAAAAB8EtQrRJ8yZUoeeOCBXHDBBVmyZEmuu+66XHXVVZk0aVJj1QcAAAAA8JGOPfbYTJgwobhfVla23rZkyZL1+r7vpptuSqtWrXLxxRcnSWbOnJnhw4cXV9cYNWpUZs+evd59582bl3322SdbbbVV2rdvn8997nN55513GvW7flIsWbIk7dq1S8eOHdc7duONN2bQoEFp1apVhg0bljvuuGPzF9hA6hWif+pTn8ott9yS66+/PkOHDs3555+fH//4x5k4cWJj1QcAAAAAUG/7779/li1bVmfbYYcdNtj3Zz/7WSZOnJiZM2fm9NNPT5Jsv/32ufDCC7Nw4cIsWLAg++yzTw4++OA89thjxfPmzZuX/fffP/vtt18efPDBzJ8/PyeffHLKy+sVuzZLa9euzZFHHpnPfvaz6x3785//nCOPPDJf+9rX8vDDD2fChAmZMGFCFi9e3ASVbrp6/9c86KCD8uijj+bdd9/N448/nhNPPLEx6gIAAAAA2GhVVVXp1q1bna2iomK9fj/84Q9zyimn5IYbbshxxx1XbB8/fnwOOOCA9O/fPwMGDMj3v//9tG3bNg888ECxz5QpU3LqqafmrLPOypAhQzJw4MAcfvjhqaqqKlnX3nvvnVNOOSWTJ09Op06d0rVr11x99dV56623ctxxx6Vdu3bp16/ferPeFy9enHHjxqVt27bp2rVrvvrVr+a1114rHr/zzjuz1157pWPHjtlmm21y0EEH5Zlnnikef+6551JWVpabb745o0ePTps2bTJixIjMmzdvo37f73znOxk0aFAOP/zw9Y795Cc/yf77758zzzwzO+20U84///yMHDkyl112WbFPnz598r3vfS9HH3102rZtm969e+e2227Lq6++moMPPjht27bN8OHDs2DBgo2qryFt+X8lAsAWr7K8Mif3PTQn9z00leWVTV0OAADAFqe6Zk3JbW3tuo/dd03t2o/Vd3P55je/mfPPPz+33357DjnkkJL9ampqcsMNN+Stt97KqFGjkiTLly/PX/7yl3Tp0iV77LFHunbtms9//vO5//77P/K+v/jFL7LtttvmwQcfzCmnnJKvf/3rOeyww7LHHnvkoYceyn777ZevfvWrefvtt5MkK1asyD777JNddtklCxYsyJ133plXXnmlToD91ltvZerUqVmwYEHuueeelJeX55BDDkltbW2de3/729/OGWeckUWLFmXAgAE58sgjs27d//43LCsry6xZsz60/nvvvTc33nhjLr/88g0enzdvXsaMGVOnbezYsesF9j/60Y+y55575uGHH86BBx6Yr371qzn66KPzla98JQ899FD69u2bo48+OoVC4SN/08YkaQCg2asoK8/wDn2bugwAAIAt1imP/KjksaHtd8yp/Q4rfj790cvWC8vfN6Btz5wx4Kji52mPXZHV69ZfP/yqkd/chGrfc/vtt6dt27bFz+PGjcuNN95Y/Dx79uzceuutueeee7LPPvts8BqPPvpoRo0alXfffTdt27bNLbfcksGDBydJ/va3vyVJzjvvvFx00UXZeeed8+///u/Zd999s3jx4vTv379kbSNGjMh3vvOdJMm0adNy4YUXZtttty2u+nHOOedk5syZ+e///u985jOfyWWXXZZddtklF1xwQfEa11xzTXr27JmnnnoqAwYMyJe+9KU697jmmmvSuXPn/PWvf83QoUOL7WeccUYOPPDAJMn06dMzZMiQLFmyJIMGDUqSDBw4MB06dChZ++uvv55jjz02v/rVr9K+ffsN9nn55ZfTtWvXOm1du3bNyy+/XKftgAMOyEknnVTnO3/qU5/KYYe99+fpm9/8ZkaNGpVXXnkl3bp1K1lTYxOiAwAAAABbnNGjR2fmzJnFz1tttVWd48OHD89rr72Wc889N5/+9KfrBO7vGzhwYBYtWpSVK1fmpptuyjHHHJO5c+dm8ODBxRneJ510UnEZmF122SX33HNPrrnmmsyYMaNkbcOHDy/uV1RUZJtttsmwYcOKbe8H0MuXL0+SPPLII7nvvvs2WOMzzzyTAQMG5Omnn84555yTv/zlL3nttdeLine truncated
|
||||
"text/plain": [
|
||||
"<Figure size 1500x300 with 1 Axes>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"colors = [\n",
|
||||
" color.convert(\"srgb\")\n",
|
||||
" for color in Color.steps(['lch(75% 50 0)', 'lch(75% 50 300)'], steps=len(destinations), space='lch', hue='longer')\n",
|
||||
"]\n",
|
||||
"\n",
|
||||
"colorful_destinations = list(zip(destinations, colors))\n",
|
||||
"\n",
|
||||
"for label, start_loc in all_starts.items():\n",
|
||||
" fig, axes = plt.subplots(1, 1, figsize=(15, 3))\n",
|
||||
" \n",
|
||||
" for durations, dest in zip(all_trips[label], colorful_destinations):\n",
|
||||
" axes.hist(durations, bins=20, alpha=0.7, color=dest[1].to_string(hex=True))\n",
|
||||
" axes.axvline(np.mean(durations), color=dest[1].to_string(hex=True), linestyle='--', \n",
|
||||
" label=f'{dest[0]} mean: {np.mean(durations):.0f}m')\n",
|
||||
" \n",
|
||||
" axes.set_title(label)\n",
|
||||
" axes.set_xlabel('Duration (minutes)')\n",
|
||||
" axes.legend()\n",
|
||||
"\n",
|
||||
" axes.set_xlim(20, 90)\n",
|
||||
" \n",
|
||||
" plt.tight_layout()\n",
|
||||
" plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7bf48fc2-1cae-448a-ac20-fc7afaa82c9b",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Fresh Python3.12",
|
||||
"language": "python",
|
||||
"name": "fresh-python312"
|
||||
},
|
||||
"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.12.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in new issue
Block a user