Skip to content

Commit 78a8adf

Browse files
authored
Merge branch 'main' into main
2 parents cb39276 + 29f9126 commit 78a8adf

File tree

4 files changed

+531
-317
lines changed

4 files changed

+531
-317
lines changed

notebooks/fundamental_diagram.ipynb

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,15 @@
245245
" nts[name] = nt"
246246
]
247247
},
248+
{
249+
"cell_type": "code",
250+
"execution_count": null,
251+
"metadata": {},
252+
"outputs": [],
253+
"source": [
254+
"len(nts)"
255+
]
256+
},
248257
{
249258
"cell_type": "markdown",
250259
"metadata": {},
@@ -260,11 +269,18 @@
260269
"source": [
261270
"import matplotlib.pyplot as plt\n",
262271
"\n",
272+
"from pedpy import plot_nt\n",
273+
"\n",
274+
"prop_cycle = plt.rcParams[\"axes.prop_cycle\"]\n",
275+
"colors = prop_cycle.by_key()[\"color\"]\n",
276+
"\n",
263277
"fig = plt.figure(figsize=(7, 7))\n",
264278
"ax1 = fig.add_subplot(111)\n",
279+
"ii = 0\n",
265280
"\n",
266281
"for name, nt in nts.items():\n",
267-
" ax1.plot(nt.time, nt.cumulative_pedestrians, label=name)\n",
282+
" plot_nt(axes=ax1, nt=nt, label=name, color=colors[ii])\n",
283+
" ii += 1\n",
268284
"\n",
269285
"ax1.legend()\n",
270286
"ax1.set_xlabel(\"time / s\")\n",
@@ -498,12 +514,11 @@
498514
"metadata": {},
499515
"outputs": [],
500516
"source": [
517+
"from pedpy import PEDPY_BLUE, PEDPY_RED, plot_density, plot_speed\n",
518+
"\n",
501519
"fig, ax = plt.subplots(nrows=len(trajectories.values()), ncols=2, figsize=(20, 60))\n",
502520
"row = 0\n",
503521
"\n",
504-
"ax[row, 1].set_title(\"Velocity\", size=\"xx-large\")\n",
505-
"ax[row, 0].set_title(\"Density\", size=\"xx-large\")\n",
506-
"\n",
507522
"for name, trajectory in trajectories.items():\n",
508523
" ax[row, 0].annotate(\n",
509524
" name,\n",
@@ -517,27 +532,23 @@
517532
" rotation=90,\n",
518533
" )\n",
519534
"\n",
520-
" ax[row, 0].plot(\n",
521-
" classic_densities[name][FRAME_COL],\n",
522-
" classic_densities[name][DENSITY_COL],\n",
523-
" alpha=1,\n",
524-
" )\n",
535+
" plot_density(axes=ax[row, 0], density=classic_densities[name], color=PEDPY_BLUE)\n",
525536
" ax[row, 0].set_xlim(left=0)\n",
526537
" ax[row, 0].set_ylim(bottom=0, top=4)\n",
527-
" ax[row, 0].set_xlabel(\"frame\")\n",
528-
" ax[row, 0].set_ylabel(\"rho / 1/m^2\")\n",
529538
" ax[row, 0].grid()\n",
530539
"\n",
531-
" ax[row, 1].plot(mean_area_speeds[name].frame, mean_area_speeds[name].speed, alpha=1)\n",
540+
" plot_speed(axes=ax[row, 1], speed=mean_area_speeds[name], color=PEDPY_RED)\n",
532541
" ax[row, 1].set_xlim(\n",
533542
" left=0,\n",
534543
" )\n",
535544
" ax[row, 1].set_ylim(bottom=0, top=3)\n",
536-
" ax[row, 1].set_xlabel(\"frame\")\n",
537-
" ax[row, 1].set_ylabel(\"v / m/s\")\n",
538545
" ax[row, 1].grid()\n",
539546
"\n",
540-
" row += 1"
547+
" row += 1\n",
548+
"ax[0, 1].set_title(\"Speed\", size=\"xx-large\")\n",
549+
"ax[0, 0].set_title(\"Density\", size=\"xx-large\")\n",
550+
"\n",
551+
"plt.show()"
541552
]
542553
},
543554
{
@@ -717,12 +728,11 @@
717728
"metadata": {},
718729
"outputs": [],
719730
"source": [
731+
"from pedpy import PEDPY_BLUE, PEDPY_ORANGE, plot_density, plot_speed\n",
732+
"\n",
720733
"fig, ax = plt.subplots(nrows=len(trajectories.values()), ncols=2, figsize=(20, 60))\n",
721734
"row = 0\n",
722735
"\n",
723-
"ax[row, 1].set_title(\"Speed\", size=\"xx-large\")\n",
724-
"ax[row, 0].set_title(\"Density\", size=\"xx-large\")\n",
725-
"\n",
726736
"for name, trajectory in trajectories.items():\n",
727737
" ax[row, 0].annotate(\n",
728738
" name,\n",
@@ -736,46 +746,25 @@
736746
" rotation=90,\n",
737747
" )\n",
738748
"\n",
739-
" ax[row, 0].plot(\n",
740-
" voronoi_densities[name][FRAME_COL],\n",
741-
" voronoi_densities[name][DENSITY_COL],\n",
742-
" alpha=1,\n",
743-
" label=\"without cut-off\",\n",
744-
" )\n",
745-
" ax[row, 0].plot(\n",
746-
" voronoi_densities_cutoff[name][FRAME_COL],\n",
747-
" voronoi_densities_cutoff[name][DENSITY_COL],\n",
748-
" alpha=1,\n",
749-
" label=\"with cut-off\",\n",
750-
" )\n",
749+
" plot_density(axes=ax[row, 0], density=voronoi_densities[name], label=\"without cut-off\", color=PEDPY_BLUE)\n",
750+
" plot_density(axes=ax[row, 0], density=voronoi_densities_cutoff[name], label=\"with cut-off\", color=PEDPY_ORANGE)\n",
751751
" ax[row, 0].set_xlim(left=0)\n",
752752
" ax[row, 0].set_ylim(bottom=0, top=4)\n",
753-
" ax[row, 0].set_xlabel(\"frame\")\n",
754-
" ax[row, 0].set_ylabel(\"rho / 1/m^2\")\n",
755753
" ax[row, 0].grid()\n",
756754
" ax[row, 0].legend()\n",
757755
"\n",
758-
" ax[row, 1].plot(\n",
759-
" voronoi_speeds[name][FRAME_COL],\n",
760-
" voronoi_speeds[name][SPEED_COL],\n",
761-
" alpha=1,\n",
762-
" label=\"without cut-off\",\n",
763-
" )\n",
764-
" ax[row, 1].plot(\n",
765-
" voronoi_speeds_cutoff[name][FRAME_COL],\n",
766-
" voronoi_speeds_cutoff[name][SPEED_COL],\n",
767-
" alpha=1,\n",
768-
" label=\"with cut-off\",\n",
769-
" )\n",
756+
" plot_speed(axes=ax[row, 1], speed=voronoi_speeds[name], label=\"without cut-off\", color=PEDPY_BLUE)\n",
757+
" plot_speed(axes=ax[row, 1], speed=voronoi_speeds_cutoff[name], label=\"with cut-off\", color=PEDPY_ORANGE)\n",
770758
" ax[row, 1].set_xlim(\n",
771759
" left=0,\n",
772760
" )\n",
773761
" ax[row, 1].set_ylim(bottom=0, top=3)\n",
774-
" ax[row, 1].set_xlabel(\"frame\")\n",
775-
" ax[row, 1].set_ylabel(\"v / m/s\")\n",
776762
" ax[row, 1].grid()\n",
777763
" ax[row, 1].legend()\n",
778764
" row += 1\n",
765+
"\n",
766+
"ax[0, 1].set_title(\"Speed\", size=\"xx-large\")\n",
767+
"ax[0, 0].set_title(\"Density\", size=\"xx-large\")\n",
779768
"plt.show()"
780769
]
781770
},
@@ -1003,7 +992,6 @@
1003992
"# Start plotting\n",
1004993
"fig = plt.figure(layout=\"constrained\")\n",
1005994
"ax1 = fig.add_subplot(131, aspect=\"equal\")\n",
1006-
"ax1.set_title(\"Color by density\")\n",
1007995
"plot_voronoi_cells(\n",
1008996
" voronoi_data=combined_data,\n",
1009997
" walkable_area=walkable_area,\n",
@@ -1014,10 +1002,10 @@
10141002
" ped_size=5,\n",
10151003
" voronoi_outside_ma_alpha=0.4,\n",
10161004
" axes=ax1,\n",
1005+
" title=\"Color by density\",\n",
10171006
")\n",
10181007
"\n",
10191008
"ax2 = fig.add_subplot(132, aspect=\"equal\")\n",
1020-
"ax2.set_title(\"Color by speed\")\n",
10211009
"plot_voronoi_cells(\n",
10221010
" voronoi_data=combined_data,\n",
10231011
" walkable_area=walkable_area,\n",
@@ -1028,10 +1016,10 @@
10281016
" ped_size=5,\n",
10291017
" voronoi_outside_ma_alpha=0.4,\n",
10301018
" axes=ax2,\n",
1019+
" title=\"Color by speed\",\n",
10311020
")\n",
10321021
"\n",
10331022
"ax3 = fig.add_subplot(133, aspect=\"equal\")\n",
1034-
"ax3.set_title(\"Color by id\")\n",
10351023
"plot_voronoi_cells(\n",
10361024
" voronoi_data=combined_data,\n",
10371025
" walkable_area=walkable_area,\n",
@@ -1042,6 +1030,8 @@
10421030
" ped_size=5,\n",
10431031
" voronoi_outside_ma_alpha=0.4,\n",
10441032
" axes=ax3,\n",
1033+
" show_colorbar=False,\n",
1034+
" title=\"Color by id\",\n",
10451035
")\n",
10461036
"plt.show()"
10471037
]

0 commit comments

Comments
 (0)