Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 39 additions & 49 deletions notebooks/fundamental_diagram.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@
" nts[name] = nt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"len(nts)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -260,11 +269,18 @@
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"from pedpy import plot_nt\n",
"\n",
"prop_cycle = plt.rcParams[\"axes.prop_cycle\"]\n",
"colors = prop_cycle.by_key()[\"color\"]\n",
"\n",
"fig = plt.figure(figsize=(7, 7))\n",
"ax1 = fig.add_subplot(111)\n",
"ii = 0\n",
"\n",
"for name, nt in nts.items():\n",
" ax1.plot(nt.time, nt.cumulative_pedestrians, label=name)\n",
" plot_nt(axes=ax1, nt=nt, label=name, color=colors[ii])\n",
" ii += 1\n",
"\n",
"ax1.legend()\n",
"ax1.set_xlabel(\"time / s\")\n",
Expand Down Expand Up @@ -498,12 +514,11 @@
"metadata": {},
"outputs": [],
"source": [
"from pedpy import PEDPY_BLUE, PEDPY_RED, plot_density, plot_speed\n",
"\n",
"fig, ax = plt.subplots(nrows=len(trajectories.values()), ncols=2, figsize=(20, 60))\n",
"row = 0\n",
"\n",
"ax[row, 1].set_title(\"Velocity\", size=\"xx-large\")\n",
"ax[row, 0].set_title(\"Density\", size=\"xx-large\")\n",
"\n",
"for name, trajectory in trajectories.items():\n",
" ax[row, 0].annotate(\n",
" name,\n",
Expand All @@ -517,27 +532,23 @@
" rotation=90,\n",
" )\n",
"\n",
" ax[row, 0].plot(\n",
" classic_densities[name][FRAME_COL],\n",
" classic_densities[name][DENSITY_COL],\n",
" alpha=1,\n",
" )\n",
" plot_density(axes=ax[row, 0], density=classic_densities[name], color=PEDPY_BLUE)\n",
" ax[row, 0].set_xlim(left=0)\n",
" ax[row, 0].set_ylim(bottom=0, top=4)\n",
" ax[row, 0].set_xlabel(\"frame\")\n",
" ax[row, 0].set_ylabel(\"rho / 1/m^2\")\n",
" ax[row, 0].grid()\n",
"\n",
" ax[row, 1].plot(mean_area_speeds[name].frame, mean_area_speeds[name].speed, alpha=1)\n",
" plot_speed(axes=ax[row, 1], speed=mean_area_speeds[name], color=PEDPY_RED)\n",
" ax[row, 1].set_xlim(\n",
" left=0,\n",
" )\n",
" ax[row, 1].set_ylim(bottom=0, top=3)\n",
" ax[row, 1].set_xlabel(\"frame\")\n",
" ax[row, 1].set_ylabel(\"v / m/s\")\n",
" ax[row, 1].grid()\n",
"\n",
" row += 1"
" row += 1\n",
"ax[0, 1].set_title(\"Speed\", size=\"xx-large\")\n",
"ax[0, 0].set_title(\"Density\", size=\"xx-large\")\n",
"\n",
"plt.show()"
]
},
{
Expand Down Expand Up @@ -717,12 +728,11 @@
"metadata": {},
"outputs": [],
"source": [
"from pedpy import PEDPY_BLUE, PEDPY_ORANGE, plot_density, plot_speed\n",
"\n",
"fig, ax = plt.subplots(nrows=len(trajectories.values()), ncols=2, figsize=(20, 60))\n",
"row = 0\n",
"\n",
"ax[row, 1].set_title(\"Speed\", size=\"xx-large\")\n",
"ax[row, 0].set_title(\"Density\", size=\"xx-large\")\n",
"\n",
"for name, trajectory in trajectories.items():\n",
" ax[row, 0].annotate(\n",
" name,\n",
Expand All @@ -736,46 +746,25 @@
" rotation=90,\n",
" )\n",
"\n",
" ax[row, 0].plot(\n",
" voronoi_densities[name][FRAME_COL],\n",
" voronoi_densities[name][DENSITY_COL],\n",
" alpha=1,\n",
" label=\"without cut-off\",\n",
" )\n",
" ax[row, 0].plot(\n",
" voronoi_densities_cutoff[name][FRAME_COL],\n",
" voronoi_densities_cutoff[name][DENSITY_COL],\n",
" alpha=1,\n",
" label=\"with cut-off\",\n",
" )\n",
" plot_density(axes=ax[row, 0], density=voronoi_densities[name], label=\"without cut-off\", color=PEDPY_BLUE)\n",
" plot_density(axes=ax[row, 0], density=voronoi_densities_cutoff[name], label=\"with cut-off\", color=PEDPY_ORANGE)\n",
" ax[row, 0].set_xlim(left=0)\n",
" ax[row, 0].set_ylim(bottom=0, top=4)\n",
" ax[row, 0].set_xlabel(\"frame\")\n",
" ax[row, 0].set_ylabel(\"rho / 1/m^2\")\n",
" ax[row, 0].grid()\n",
" ax[row, 0].legend()\n",
"\n",
" ax[row, 1].plot(\n",
" voronoi_speeds[name][FRAME_COL],\n",
" voronoi_speeds[name][SPEED_COL],\n",
" alpha=1,\n",
" label=\"without cut-off\",\n",
" )\n",
" ax[row, 1].plot(\n",
" voronoi_speeds_cutoff[name][FRAME_COL],\n",
" voronoi_speeds_cutoff[name][SPEED_COL],\n",
" alpha=1,\n",
" label=\"with cut-off\",\n",
" )\n",
" plot_speed(axes=ax[row, 1], speed=voronoi_speeds[name], label=\"without cut-off\", color=PEDPY_BLUE)\n",
" plot_speed(axes=ax[row, 1], speed=voronoi_speeds_cutoff[name], label=\"with cut-off\", color=PEDPY_ORANGE)\n",
" ax[row, 1].set_xlim(\n",
" left=0,\n",
" )\n",
" ax[row, 1].set_ylim(bottom=0, top=3)\n",
" ax[row, 1].set_xlabel(\"frame\")\n",
" ax[row, 1].set_ylabel(\"v / m/s\")\n",
" ax[row, 1].grid()\n",
" ax[row, 1].legend()\n",
" row += 1\n",
"\n",
"ax[0, 1].set_title(\"Speed\", size=\"xx-large\")\n",
"ax[0, 0].set_title(\"Density\", size=\"xx-large\")\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -1003,7 +992,6 @@
"# Start plotting\n",
"fig = plt.figure(layout=\"constrained\")\n",
"ax1 = fig.add_subplot(131, aspect=\"equal\")\n",
"ax1.set_title(\"Color by density\")\n",
"plot_voronoi_cells(\n",
" voronoi_data=combined_data,\n",
" walkable_area=walkable_area,\n",
Expand All @@ -1014,10 +1002,10 @@
" ped_size=5,\n",
" voronoi_outside_ma_alpha=0.4,\n",
" axes=ax1,\n",
" title=\"Color by density\",\n",
")\n",
"\n",
"ax2 = fig.add_subplot(132, aspect=\"equal\")\n",
"ax2.set_title(\"Color by speed\")\n",
"plot_voronoi_cells(\n",
" voronoi_data=combined_data,\n",
" walkable_area=walkable_area,\n",
Expand All @@ -1028,10 +1016,10 @@
" ped_size=5,\n",
" voronoi_outside_ma_alpha=0.4,\n",
" axes=ax2,\n",
" title=\"Color by speed\",\n",
")\n",
"\n",
"ax3 = fig.add_subplot(133, aspect=\"equal\")\n",
"ax3.set_title(\"Color by id\")\n",
"plot_voronoi_cells(\n",
" voronoi_data=combined_data,\n",
" walkable_area=walkable_area,\n",
Expand All @@ -1042,6 +1030,8 @@
" ped_size=5,\n",
" voronoi_outside_ma_alpha=0.4,\n",
" axes=ax3,\n",
" show_colorbar=False,\n",
" title=\"Color by id\",\n",
")\n",
"plt.show()"
]
Expand Down
Loading