diff --git a/ca_transit_speed_maps/01_new_speedmaps.ipynb b/ca_transit_speed_maps/01_new_speedmaps.ipynb index d7f023013..387c7fb81 100644 --- a/ca_transit_speed_maps/01_new_speedmaps.ipynb +++ b/ca_transit_speed_maps/01_new_speedmaps.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 62, "id": "46898b5c-b5cc-4096-ab68-8c3e42fab870", "metadata": {}, "outputs": [], @@ -12,8 +12,9 @@ "warnings.filterwarnings('ignore')\n", "\n", "import calitp_data_analysis.magics\n", + "from calitp_data_analysis import calitp_color_palette\n", "\n", - "from rt_analysis import rt_filter_map_plot\n", + "# from rt_analysis import rt_filter_map_plot\n", "import build_speedmaps_index\n", "\n", "from IPython.display import display, Markdown\n", @@ -47,7 +48,7 @@ "outputs": [], "source": [ "## parameters cell\n", - "itp_id = 182" + "itp_id = 300" ] }, { @@ -309,28 +310,32 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 13, "id": "d483e182-b36c-487e-a194-7a9e48d5b32f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'time_of_day' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[13], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m time_of_day_lower \u001b[38;5;241m=\u001b[39m \u001b[43mtime_of_day\u001b[49m\u001b[38;5;241m.\u001b[39mlower()\u001b[38;5;241m.\u001b[39mreplace(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m_\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", + "\u001b[0;31mNameError\u001b[0m: name 'time_of_day' is not defined" + ] + } + ], "source": [ "time_of_day_lower = time_of_day.lower().replace(' ', '_')" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "id": "51e108ee-19f5-4266-8848-fb5ac57f5108", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "writing to calitp-map-tiles/testing/182_pm_peak_new.geojson.gz\n" - ] - } - ], + "outputs": [], "source": [ "# TODO clone render method from RtFilterMapper, to utils\n", "speedmap_state = shared_utils.rt_utils.set_state_export(\n", @@ -341,33 +346,855 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": null, "id": "75f2695e-4b80-4d91-8dce-1fa8e347729b", "metadata": {}, + "outputs": [], + "source": [ + "speedmap_state" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "5af14034-e54b-4d00-bf78-5882ae3a7b24", + "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'state_dict': {'name': 'null',\n", - " 'layers': [{'name': 'Speedmap Segs PM Peak 2024-10-16',\n", - " 'url': 'https://storage.googleapis.com/calitp-map-tiles/testing/182_new.geojson.gz',\n", - " 'properties': {'stroked': False,\n", - " 'highlight_saturation_multiplier': 0.5,\n", - " 'tooltip_speed_key': 'p20_mph'},\n", - " 'type': 'speedmap'}],\n", - " 'lat_lon': (34.0539357609537, -118.29997523003668),\n", - " 'zoom': 13,\n", - " 'legend_url': 'https://storage.googleapis.com/calitp-map-tiles/speeds_legend_color_access.svg'},\n", - " 'spa_link': 'https://embeddable-maps.calitp.org/?state=eyJuYW1lIjogIm51bGwiLCAibGF5ZXJzIjogW3sibmFtZSI6ICJTcGVlZG1hcCBTZWdzIFBNIFBlYWsgMjAyNC0xMC0xNiIsICJ1cmwiOiAiaHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL2NhbGl0cC1tYXAtdGlsZXMvdGVzdGluZy8xODJfbmV3Lmdlb2pzb24uZ3oiLCAicHJvcGVydGllcyI6IHsic3Ryb2tlZCI6IGZhbHNlLCAiaGlnaGxpZ2h0X3NhdHVyYXRpb25fbXVsdGlwbGllciI6IDAuNSwgInRvb2x0aXBfc3BlZWRfa2V5IjogInAyMF9tcGgifSwgInR5cGUiOiAic3BlZWRtYXAifV0sICJsYXRfbG9uIjogWzM0LjA1MzkzNTc2MDk1MzcsIC0xMTguMjk5OTc1MjMwMDM2NjhdLCAiem9vbSI6IDEzLCAibGVnZW5kX3VybCI6ICJodHRwczovL3N0b3JhZ2UuZ29vZ2xlYXBpcy5jb20vY2FsaXRwLW1hcC10aWxlcy9zcGVlZHNfbGVnZW5kX2NvbG9yX2FjY2Vzcy5zdmcifQ=='}" + "Index(['schedule_gtfs_dataset_key', 'shape_array_key', 'shape_id', 'route_id',\n", + " 'direction_id', 'stop_pair', 'stop_pair_name', 'segment_id',\n", + " 'time_of_day', 'p50_mph', 'n_trips', 'p20_mph', 'p80_mph', 'name',\n", + " 'caltrans_district', 'organization_source_record_id',\n", + " 'organization_name', 'base64_url', 'geometry', 'n_trips_sch',\n", + " 'trips_hr_sch', 'route_short_name'],\n", + " dtype='object')" ] }, - "execution_count": 88, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "speedmap_state" + "speedmap_segs.columns" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdf9c56a-0ad8-44b8-8bed-a677c9d36037", + "metadata": {}, + "outputs": [], + "source": [ + "speedmap_segs" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "df0b34b1-f3fd-4081-8598-eed78541da71", + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'vega_datasets'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[15], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01maltair\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01malt\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mvega_datasets\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m data\n\u001b[1;32m 4\u001b[0m source \u001b[38;5;241m=\u001b[39m data\u001b[38;5;241m.\u001b[39mbarley()\n\u001b[1;32m 6\u001b[0m error_bars \u001b[38;5;241m=\u001b[39m alt\u001b[38;5;241m.\u001b[39mChart(source)\u001b[38;5;241m.\u001b[39mmark_errorbar(extent\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mstdev\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mencode(\n\u001b[1;32m 7\u001b[0m alt\u001b[38;5;241m.\u001b[39mY(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myield:Q\u001b[39m\u001b[38;5;124m\"\u001b[39m)\u001b[38;5;241m.\u001b[39mscale(zero\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m),\n\u001b[1;32m 8\u001b[0m alt\u001b[38;5;241m.\u001b[39mX(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mvariety:N\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 9\u001b[0m )\n", + "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'vega_datasets'" + ] + } + ], + "source": [ + "import altair as alt\n", + "from vega_datasets import data\n", + "\n", + "source = data.barley()\n", + "\n", + "error_bars = alt.Chart(source).mark_errorbar(extent=\"stdev\").encode(\n", + " alt.Y(\"yield:Q\").scale(zero=False),\n", + " alt.X(\"variety:N\"),\n", + ")\n", + "\n", + "points = alt.Chart(source).mark_point(\n", + " filled=True,\n", + " color=\"black\",\n", + ").encode(\n", + " alt.Y(\"mean(yield)\"),\n", + " alt.X(\"variety:N\"),\n", + ")\n", + "\n", + "error_bars + points" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "ded22024-1209-419c-bfce-22499d58718a", + "metadata": {}, + "outputs": [ + { + "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", + " \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", + " \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", + "
time_of_dayp50_mphp20_mphp80_mphy_erry_err2
5265AM Peak13.0013.0013.0013.0013.00
5266AM Peak22.5822.5822.5822.5822.58
5267AM Peak7.317.317.317.317.31
5268AM Peak15.7215.7215.7215.7215.72
5269AM Peak18.6218.6218.6218.6218.62
.....................
126376Early AM55.4555.4555.4555.4555.45
126377Early AM54.6254.6254.6254.6254.62
126378Early AM8.228.228.228.228.22
126379Early AM17.6017.6017.6017.6017.60
126380Early AM16.0216.0216.0216.0216.02
\n", + "

121116 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " time_of_day p50_mph p20_mph p80_mph y_err y_err2\n", + "5265 AM Peak 13.00 13.00 13.00 13.00 13.00\n", + "5266 AM Peak 22.58 22.58 22.58 22.58 22.58\n", + "5267 AM Peak 7.31 7.31 7.31 7.31 7.31\n", + "5268 AM Peak 15.72 15.72 15.72 15.72 15.72\n", + "5269 AM Peak 18.62 18.62 18.62 18.62 18.62\n", + "... ... ... ... ... ... ...\n", + "126376 Early AM 55.45 55.45 55.45 55.45 55.45\n", + "126377 Early AM 54.62 54.62 54.62 54.62 54.62\n", + "126378 Early AM 8.22 8.22 8.22 8.22 8.22\n", + "126379 Early AM 17.60 17.60 17.60 17.60 17.60\n", + "126380 Early AM 16.02 16.02 16.02 16.02 16.02\n", + "\n", + "[121116 rows x 6 columns]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df >> group_by" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "23e5a153-f608-4aad-b9ca-8cabc7f90017", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "alt.Chart(df).mark_errorbar().encode(\n", + " # y = alt.Y(\"p50_mph:Q\").scale(zero=False),\n", + " y = alt.Y(\"p50_mph:Q\"),\n", + " yError=(\"y_err:Q\"),\n", + " yError2=(\"y_err2:Q\"),\n", + " x = alt.X(\"time_of_day:N\", sort=['Early AM', 'AM Peak', 'Midday', 'PM Peak', 'Evening', 'Owl']),\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "id": "3feb8dbd-afea-4e30-8fd9-544875699e70", + "metadata": {}, + "outputs": [ + { + "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", + " \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", + "
time_of_dayp50_mphp20_mphp80_mphy_erry_err2
0AM Peak13.3510.7416.612.613.26
1Early AM15.3712.8518.332.522.96
2Evening17.1715.0119.622.162.45
3Midday12.789.9616.412.823.63
4Owl19.2517.1321.242.121.99
5PM Peak12.7810.1516.372.633.59
\n", + "
" + ], + "text/plain": [ + " time_of_day p50_mph p20_mph p80_mph y_err y_err2\n", + "0 AM Peak 13.35 10.74 16.61 2.61 3.26\n", + "1 Early AM 15.37 12.85 18.33 2.52 2.96\n", + "2 Evening 17.17 15.01 19.62 2.16 2.45\n", + "3 Midday 12.78 9.96 16.41 2.82 3.63\n", + "4 Owl 19.25 17.13 21.24 2.12 1.99\n", + "5 PM Peak 12.78 10.15 16.37 2.63 3.59" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "id": "52e9a61d-d9bc-474d-a6ed-2120099d0592", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 -2.61\n", + "1 -2.52\n", + "2 -2.16\n", + "3 -2.82\n", + "4 -2.12\n", + "5 -2.63\n", + "dtype: float64" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "-(df['p50_mph'] - df['p20_mph'])" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "id": "bba0a5ba-a95a-4923-b04f-800b74e63a98", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "branca.colormap.StepColormap" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(cmap)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "id": "64083c0e-4283-4554-ae8a-3e4e8a34ce21", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['__call__',\n", + " '__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " '_children',\n", + " '_env',\n", + " '_get_self_bounds',\n", + " '_id',\n", + " '_name',\n", + " '_parent',\n", + " '_repr_html_',\n", + " '_template',\n", + " 'add_child',\n", + " 'add_children',\n", + " 'add_to',\n", + " 'caption',\n", + " 'colors',\n", + " 'get_bounds',\n", + " 'get_name',\n", + " 'get_root',\n", + " 'index',\n", + " 'render',\n", + " 'rgb_bytes_tuple',\n", + " 'rgb_hex_str',\n", + " 'rgba_bytes_tuple',\n", + " 'rgba_floats_tuple',\n", + " 'rgba_hex_str',\n", + " 'save',\n", + " 'scale',\n", + " 'to_dict',\n", + " 'to_json',\n", + " 'to_linear',\n", + " 'vmax',\n", + " 'vmin']" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dir(cmap)" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "df62d501-9ef1-4203-a881-4e381651590e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[None, None], [None, None]]" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cmap.get_bounds()" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "id": "7c9501e3-24e7-4677-beaf-fa138d6a0837", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['__call__',\n", + " '__class__',\n", + " '__delattr__',\n", + " '__dict__',\n", + " '__dir__',\n", + " '__doc__',\n", + " '__eq__',\n", + " '__format__',\n", + " '__ge__',\n", + " '__getattribute__',\n", + " '__gt__',\n", + " '__hash__',\n", + " '__init__',\n", + " '__init_subclass__',\n", + " '__le__',\n", + " '__lt__',\n", + " '__module__',\n", + " '__ne__',\n", + " '__new__',\n", + " '__reduce__',\n", + " '__reduce_ex__',\n", + " '__repr__',\n", + " '__setattr__',\n", + " '__sizeof__',\n", + " '__str__',\n", + " '__subclasshook__',\n", + " '__weakref__',\n", + " '_children',\n", + " '_env',\n", + " '_get_self_bounds',\n", + " '_id',\n", + " '_name',\n", + " '_parent',\n", + " '_repr_html_',\n", + " '_template',\n", + " 'add_child',\n", + " 'add_children',\n", + " 'add_to',\n", + " 'caption',\n", + " 'colors',\n", + " 'get_bounds',\n", + " 'get_name',\n", + " 'get_root',\n", + " 'index',\n", + " 'render',\n", + " 'rgb_bytes_tuple',\n", + " 'rgb_hex_str',\n", + " 'rgba_bytes_tuple',\n", + " 'rgba_floats_tuple',\n", + " 'rgba_hex_str',\n", + " 'save',\n", + " 'scale',\n", + " 'to_dict',\n", + " 'to_json',\n", + " 'to_linear',\n", + " 'vmax',\n", + " 'vmin']" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dir(cmap.scale())" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "id": "6d2ccae7-a8b6-4e44-9095-17e4e416ea29", + "metadata": {}, + "outputs": [ + { + "ename": "SchemaValidationError", + "evalue": "`Scale` has no parameter named 'children'\n\nExisting parameter names are:\nalign domain exponent paddingOuter round \nbase domainMax interpolate range scheme \nbins domainMid nice rangeMax type \nclamp domainMin padding rangeMin zero \nconstant domainRaw paddingInner reverse \n\nSee the help for `Scale` to read the full description of these parameters", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mSchemaValidationError\u001b[0m Traceback (most recent call last)", + "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/altair/vegalite/v5/api.py:961\u001b[0m, in \u001b[0;36mTopLevelMixin.to_dict\u001b[0;34m(self, validate, format, ignore, context)\u001b[0m\n\u001b[1;32m 956\u001b[0m context[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mtop_level\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 958\u001b[0m \u001b[38;5;66;03m# TopLevelMixin instance does not necessarily have to_dict defined\u001b[39;00m\n\u001b[1;32m 959\u001b[0m \u001b[38;5;66;03m# but due to how Altair is set up this should hold.\u001b[39;00m\n\u001b[1;32m 960\u001b[0m \u001b[38;5;66;03m# Too complex to type hint right now\u001b[39;00m\n\u001b[0;32m--> 961\u001b[0m vegalite_spec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mTopLevelMixin\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcopy\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mto_dict\u001b[49m\u001b[43m(\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore[misc]\u001b[39;49;00m\n\u001b[1;32m 962\u001b[0m \u001b[43m \u001b[49m\u001b[43mvalidate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mvalidate\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mignore\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mignore\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcontext\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mcontext\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpre_transform\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 963\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 965\u001b[0m \u001b[38;5;66;03m# TODO: following entries are added after validation. Should they be validated?\u001b[39;00m\n\u001b[1;32m 966\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m is_top_level:\n\u001b[1;32m 967\u001b[0m \u001b[38;5;66;03m# since this is top-level we add $schema if it's missing\u001b[39;00m\n", + "File \u001b[0;32m/opt/conda/lib/python3.9/site-packages/altair/utils/schemapi.py:978\u001b[0m, in \u001b[0;36mSchemaBase.to_dict\u001b[0;34m(self, validate, ignore, context)\u001b[0m\n\u001b[1;32m 971\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalidate(result)\n\u001b[1;32m 972\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m jsonschema\u001b[38;5;241m.\u001b[39mValidationError \u001b[38;5;28;01mas\u001b[39;00m err:\n\u001b[1;32m 973\u001b[0m \u001b[38;5;66;03m# We do not raise `from err` as else the resulting\u001b[39;00m\n\u001b[1;32m 974\u001b[0m \u001b[38;5;66;03m# traceback is very long as it contains part\u001b[39;00m\n\u001b[1;32m 975\u001b[0m \u001b[38;5;66;03m# of the Vega-Lite schema. It would also first\u001b[39;00m\n\u001b[1;32m 976\u001b[0m \u001b[38;5;66;03m# show the less helpful ValidationError instead of\u001b[39;00m\n\u001b[1;32m 977\u001b[0m \u001b[38;5;66;03m# the more user friendly SchemaValidationError\u001b[39;00m\n\u001b[0;32m--> 978\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m SchemaValidationError(\u001b[38;5;28mself\u001b[39m, err) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 979\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m result\n", + "\u001b[0;31mSchemaValidationError\u001b[0m: `Scale` has no parameter named 'children'\n\nExisting parameter names are:\nalign domain exponent paddingOuter round \nbase domainMax interpolate range scheme \nbins domainMid nice rangeMax type \nclamp domainMin padding rangeMin zero \nconstant domainRaw paddingInner reverse \n\nSee the help for `Scale` to read the full description of these parameters" + ] + }, + { + "data": { + "text/plain": [ + "alt.LayerChart(...)" + ] + }, + "execution_count": 69, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df = speedmap_segs[['time_of_day', 'p50_mph', 'p20_mph', 'p80_mph']]\n", + "df = df >> group_by(_.time_of_day) >> summarize(p50_mph = _.p50_mph.quantile(.5),\n", + " p20_mph = _.p20_mph.quantile(.5),\n", + " p80_mph = _.p80_mph.quantile(.5),)\n", + "df['y_err'] = -(df['p50_mph'] - df['p20_mph'])\n", + "df['y_err2'] = df['p80_mph'] - df['p50_mph']\n", + "\n", + "error_bars = alt.Chart(df).mark_errorbar(thickness=5,\n", + " color='gray',\n", + " opacity=.8).encode(\n", + " # y = alt.Y(\"p50_mph:Q\").scale(zero=False),\n", + " y = alt.Y(\"p50_mph:Q\").scale(zero=False),\n", + " yError=(\"y_err:Q\"),\n", + " yError2=(\"y_err2:Q\"),\n", + " x = alt.X(\"time_of_day:N\", sort=['Early AM', 'AM Peak', 'Midday', 'PM Peak', 'Evening', 'Owl']),\n", + ")\n", + "\n", + "points = alt.Chart(df).mark_point(\n", + " filled=True,\n", + " # color=\"black\",\n", + ").encode(\n", + " alt.Y(\"p50_mph:Q\"),\n", + " alt.X(\"time_of_day:N\", sort=['Early AM', 'AM Peak', 'Midday', 'PM Peak', 'Evening', 'Owl']),\n", + " color=alt.Color('p50_mph', scale=cmap)\n", + ")\n", + "\n", + "error_bars + points\n", + "# error_bars" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "551c030e-6f02-49d8-92f2-1d283fd3bc94", + "metadata": {}, + "outputs": [], + "source": [ + "source = pd.DataFrame({\n", + " \"yield_error\": [7.5522, 6.9775, 3.9167, 11.9732],\n", + " \"yield_center\": [32.4, 30.96667, 33.966665, 30.45],\n", + " \"variety\": [\"Glabron\", \"Manchuria\", \"No. 457\", \"No. 462\"],\n", + "})\n", + "\n", + "bar = alt.Chart(source).mark_errorbar().encode(\n", + " x=alt.X(\"yield_center:Q\").scale(zero=False).title(\"yield\"),\n", + " xError=(\"yield_error:Q\"),\n", + " y=alt.Y(\"variety:N\"),\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "8dd67db3-eeb8-4b0b-ae2e-d5e3a96f1de6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.Chart(...)" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bar" ] }, {