From be1c4f00d86ddd132600047b98c36d267456c84b Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Wed, 3 Dec 2025 13:01:41 +0100 Subject: [PATCH 01/13] introduced line_width option, default empty title, dataframe type in plot density, speed and acceleration --- pedpy/plotting/plotting.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index c254739c..95d2d417 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -19,6 +19,7 @@ from numpy.typing import NDArray from pedpy.column_identifier import ( + ACC_COL, CUMULATED_COL, DENSITY_COL, DENSITY_SP1_COL, @@ -152,12 +153,13 @@ def _plot_series( # pylint: disable=too-many-arguments x: pd.Series, y: pd.Series, color: str, + line_width: str, x_label: str, y_label: str, **kwargs: Any, ) -> matplotlib.axes.Axes: axes.set_title(title) - axes.plot(x, y, color=color, **kwargs) + axes.plot(x, y, color=color, linewidth=line_width, **kwargs) axes.set_xlabel(x_label) axes.set_ylabel(y_label) return axes @@ -424,6 +426,7 @@ def plot_density( Keyword Args: color (optional): color of the plot title (optional): title of the plot + line_width (optional): line width of the density timeseries x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -434,16 +437,18 @@ def plot_density( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - title = kwargs.pop("title", "density over time") + line_width = kwargs.pop("line_width", 1.0) + title = kwargs.pop("title", "") x_label = kwargs.pop("x_label", "frame") y_label = kwargs.pop("y_label", "$\\rho$ / 1/$m^2$") return _plot_series( axes=axes, title=title, - x=density.index, + x=density[FRAME_COL], y=density[DENSITY_COL], color=color, + linewidth=line_width, x_label=x_label, y_label=y_label, **kwargs, @@ -452,7 +457,7 @@ def plot_density( def plot_speed( *, - speed: pd.Series, + speed: pd.DataFrame, axes: Optional[matplotlib.axes.Axes] = None, **kwargs: Any, ) -> matplotlib.axes.Axes: @@ -467,6 +472,7 @@ def plot_speed( Keyword Args: color (optional): color of the plot + line_width (optional): line width of the speed timeseries title (optional): title of the plot x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -478,16 +484,18 @@ def plot_speed( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - title = kwargs.pop("title", "speed over time") + line_width = kwargs.pop("line_width", 1.5) + title = kwargs.pop("title", "") x_label = kwargs.pop("x_label", "frame") y_label = kwargs.pop("y_label", "v / m/s") return _plot_series( axes=axes, title=title, - x=speed.index, - y=speed, + x=speed[FRAME_COL], + y=speed[SPEED_COL], color=color, + line_width=line_width, x_label=x_label, y_label=y_label, **kwargs, @@ -633,7 +641,7 @@ def plot_flow( def plot_acceleration( *, - acceleration: pd.Series, + acceleration: pd.DataFrame, axes: Optional[matplotlib.axes.Axes] = None, **kwargs: Any, ) -> matplotlib.axes.Axes: @@ -648,6 +656,7 @@ def plot_acceleration( Keyword Args: color (optional): color of the plot + line_width (optional): line width of the acceleration time series title (optional): title of the plot x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -659,16 +668,18 @@ def plot_acceleration( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - title = kwargs.pop("title", "acceleration over time") + line_width = kwargs.pop("line_width", 1.5) + title = kwargs.pop("title", "") x_label = kwargs.pop("x_label", "frame") y_label = kwargs.pop("y_label", "a / $m/s^2$") return _plot_series( axes=axes, title=title, - x=acceleration.index, - y=acceleration, + x=acceleration[FRAME_COL], + y=acceleration[ACC_COL], color=color, + line_width=line_width, x_label=x_label, y_label=y_label, **kwargs, From 3979963f2afab8fe92da8119a734fcd980395353 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Wed, 3 Dec 2025 13:21:32 +0100 Subject: [PATCH 02/13] update api reference of plot_*_at_line --- pedpy/plotting/plotting.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 95d2d417..ab4a830e 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -209,6 +209,10 @@ def plot_speed_at_line( label_species1 (optional): tag of species 1 in the legend label_species2 (optional): tag of species 2 in the legend label_total (optional): tag of total speed in the legend + line_width (optional): line width of the density timeseries + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis + Returns: matplotlib.axes.Axes instance where the speeds are plotted @@ -219,13 +223,13 @@ def plot_speed_at_line( color_sp1 = kwargs.get("color_species1", PEDPY_BLUE) color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) - title = kwargs.get("title", "Speed at Line") + title = kwargs.get("title", "") x_label = kwargs.get("x_label", "Frame") y_label = kwargs.get("y_label", "v / m/s") label_sp1 = kwargs.get("lable_species1", "species 1") label_sp2 = kwargs.get("lable_species2", "species 2") label_total = kwargs.get("lable_total", "total") - line_width = kwargs.get("line_width", 0.5) + line_width = kwargs.get("line_width", 1.5) return _plot_multiple_series( axes=axes, @@ -268,6 +272,9 @@ def plot_density_at_line( label_species1 (optional): tag of species 1 in the legend label_species2 (optional): tag of species 2 in the legend label_total (optional): tag of total speed in the legend + line_width (optional): line width of the density timeseries + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis Returns: matplotlib.axes.Axes instance where the densities are plotted @@ -278,13 +285,13 @@ def plot_density_at_line( color_sp1 = kwargs.get("color_species1", PEDPY_BLUE) color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) - title = kwargs.get("title", "Density at Line") + title = kwargs.get("title", "") x_label = kwargs.get("x_label", "Frame") y_label = kwargs.get("y_label", "$\\rho$ / 1/$m^2$") - label_sp1 = kwargs.get("lable_species1", "species 1") - label_sp2 = kwargs.get("lable_species2", "species 2") - label_total = kwargs.get("lable_total", "total") - line_width = kwargs.get("line_width", 0.5) + label_sp1 = kwargs.get("label_species1", "species 1") + label_sp2 = kwargs.get("label_species2", "species 2") + label_total = kwargs.get("label_total", "total") + line_width = kwargs.get("line_width", 1.5) return _plot_multiple_series( axes=axes, @@ -327,6 +334,9 @@ def plot_flow_at_line( label_species1 (optional): tag of species 1 in the legend label_species2 (optional): tag of species 2 in the legend label_total (optional): tag of total speed in the legend + line_width (optional): line width of the density timeseries + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis Returns: matplotlib.axes.Axes instance where the profiles are plotted @@ -337,13 +347,13 @@ def plot_flow_at_line( color_sp1 = kwargs.get("color_species1", PEDPY_BLUE) color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) - title = kwargs.get("title", "Flow at Line") + title = kwargs.get("title", "") x_label = kwargs.get("x_label", "Frame") y_label = kwargs.get("y_label", "J / 1/s") label_sp1 = kwargs.get("lable_species1", "species 1") label_sp2 = kwargs.get("lable_species2", "species 2") label_total = kwargs.get("lable_total", "total") - line_width = kwargs.get("line_width", 0.5) + line_width = kwargs.get("line_width", 1.5) return _plot_multiple_series( axes=axes, From 45e60a05c83a6f018dc8100462dafb7cf5148afe Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Wed, 3 Dec 2025 14:59:32 +0100 Subject: [PATCH 03/13] changed plot_flow to plot_crossing_speed_flow and added optional argments marker and marker_size --- pedpy/__init__.py | 4 ++-- pedpy/plotting/plotting.py | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/pedpy/__init__.py b/pedpy/__init__.py index cba5c3d8..bcf484ea 100644 --- a/pedpy/__init__.py +++ b/pedpy/__init__.py @@ -132,10 +132,10 @@ PEDPY_PETROL, PEDPY_RED, plot_acceleration, + plot_crossing_speed_flow, plot_density, plot_density_at_line, plot_density_distribution, - plot_flow, plot_flow_at_line, plot_measurement_setup, plot_neighborhood, @@ -219,7 +219,7 @@ "plot_density", "plot_density_at_line", "plot_density_distribution", - "plot_flow", + "plot_crossing_speed_flow", "plot_flow_at_line", "plot_measurement_setup", "plot_neighborhood", diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index ab4a830e..6d6aba7b 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -153,7 +153,7 @@ def _plot_series( # pylint: disable=too-many-arguments x: pd.Series, y: pd.Series, color: str, - line_width: str, + line_width: float, x_label: str, y_label: str, **kwargs: Any, @@ -447,7 +447,7 @@ def plot_density( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - line_width = kwargs.pop("line_width", 1.0) + line_width = kwargs.pop("line_width", 1.5) title = kwargs.pop("title", "") x_label = kwargs.pop("x_label", "frame") y_label = kwargs.pop("y_label", "$\\rho$ / 1/$m^2$") @@ -458,7 +458,7 @@ def plot_density( x=density[FRAME_COL], y=density[DENSITY_COL], color=color, - linewidth=line_width, + line_width=line_width, x_label=x_label, y_label=y_label, **kwargs, @@ -611,13 +611,13 @@ def plot_density_distribution( return _plot_violin_xy(data=density.density, axes=axes, **kwargs) -def plot_flow( +def plot_crossing_speed_flow( *, flow: pd.DataFrame, axes: Optional[matplotlib.axes.Axes] = None, **kwargs: Any, ) -> matplotlib.axes.Axes: - """Plot the flow. + """Plot the relationship of mean speed and flow while crossing a measurement line. Args: flow(pd.DataFrame): flow for some given crossing_frames and nt @@ -631,6 +631,8 @@ def plot_flow( title (optional): title of the plot x_label (optional): label on the x-axis y_label (optional): label on the y-axis + marker (optional): Markerstyle + marker_size (optional): Size of the markers Returns: matplotlib.axes.Axes instance where the flow is plotted @@ -639,11 +641,13 @@ def plot_flow( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - title = kwargs.pop("title", "flow") + title = kwargs.pop("title", "") x_label = kwargs.pop("x_label", "J / 1/s") y_label = kwargs.pop("y_label", "v / m/s") + marker = kwargs.get("marker", "o") + marker_size = kwargs.get("marker_size", 16) axes.set_title(title) - axes.scatter(flow[FLOW_COL], flow[MEAN_SPEED_COL], color=color, **kwargs) + axes.scatter(flow[FLOW_COL], flow[MEAN_SPEED_COL], color=color, s=marker_size, marker=marker, **kwargs) axes.set_xlabel(x_label) axes.set_ylabel(y_label) return axes From d9c003ff438ce93cb7eae1c5e685e3bb7e86e3a8 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Wed, 3 Dec 2025 15:10:59 +0100 Subject: [PATCH 04/13] add line_width option to plot_nt --- pedpy/plotting/plotting.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 6d6aba7b..7b665c31 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -378,7 +378,7 @@ def plot_nt( axes: Optional[matplotlib.axes.Axes] = None, **kwargs: Any, ) -> matplotlib.axes.Axes: - """Plot the number of pedestrians over time. + """Plot the number of pedestrians crossing a line over time. Args: nt (pd.DataFrame): cumulative number of pedestrians over time @@ -390,6 +390,7 @@ def plot_nt( Keyword Args: color (optional): color of the plot title (optional): title of the plot + line_width (optional): line width of the N-t diagram x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -400,18 +401,17 @@ def plot_nt( axes = plt.gca() color = kwargs.pop("color", PEDPY_BLUE) - title = kwargs.pop("title", "N-t") + title = kwargs.pop("title", "") + line_width = kwargs.pop("line_width", 1.5) x_label = kwargs.pop("x_label", "t / s") - y_label = kwargs.pop( - "y_label", - r"\# pedestrians" if plt.rcParams["text.usetex"] else "# pedestrians", - ) + y_label = kwargs.pop("y_label", "cumulative pedestrians") return _plot_series( axes=axes, title=title, x=nt[TIME_COL], y=nt[CUMULATED_COL], color=color, + line_width=line_width, x_label=x_label, y_label=y_label, **kwargs, From aad23a824fb4a723df3fa48894412e3cc277c142 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 10:40:14 +0100 Subject: [PATCH 05/13] added options to plot_time_distance --- pedpy/plotting/plotting.py | 62 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 7b665c31..d94563b7 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -893,7 +893,7 @@ def plot_time_distance( # noqa: PLR0915 Args: time_distance (pd.DataFrame): DataFrame containing information on time and distance to some target - speed (pd.DataFrame): DataFrame containing speed calculation. + speed (pd.DataFrame, optional): DataFrame containing speed calculation. axes (matplotlib.axes.Axes): Axes to plot on, if None new will be created kwargs: Additional parameters to change the plot appearance, see @@ -901,7 +901,11 @@ def plot_time_distance( # noqa: PLR0915 Keyword Args: marker_color (optional): color of the markers on the plot + marker_size (optional): size of the markers + marker (optional): type of the markers line_color (optional): color of the lines on the plot + line_width (optional): width of the line sof the plot + line_alpha (optional): alpha value of the plotted lines title (optional): title of the plot x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -918,7 +922,7 @@ def _setup_plot(axes: matplotlib.axes.Axes, **kwargs: Any) -> None: **kwargs: Keyword arguments containing 'title', 'x_label' and 'y_label'. """ - title = kwargs.get("title", "Distance Plot") + title = kwargs.get("title", "") x_label = kwargs.get("x_label", "Distance / m") y_label = kwargs.get("y_label", "Time / s") @@ -930,6 +934,8 @@ def _scatter_min_data( axes: matplotlib.axes.Axes, ped_data: pd.DataFrame, color: str, + marker_size: float, + marker: str, ) -> None: """Adds a scatter plot marker at the start of a pedestrian's line. @@ -937,20 +943,24 @@ def _scatter_min_data( axes: The matplotlib axes to plot on. ped_data: DataFrame containing pedestrian data. color: Color of the scatter plot marker. + marker_size: Size of the markers. + marker: Type of marker. """ min_data = ped_data.loc[ped_data.groupby(ID_COL)[FRAME_COL].idxmin()] axes.scatter( min_data.distance, min_data.time, color=color, - s=5, - marker="o", + s=marker_size, + marker=marker, ) def _scatter_min_data_with_color( axes: matplotlib.axes.Axes, ped_data: pd.DataFrame, norm: Normalize, + marker_size: float, + marker: str, ) -> None: """Adds a scatter plot marker at the start of a pedestrian's line. @@ -961,6 +971,8 @@ def _scatter_min_data_with_color( cmap: The colormap to use for coloring the line based on speed. frame_rate: Frame rate used to adjust time values. color: Color of the scatter plot marker. + marker_size: Size of the markers. + marker: Type of marker. """ min_data = ped_data.loc[ped_data.groupby(ID_COL)[FRAME_COL].idxmin()] axes.scatter( @@ -969,14 +981,16 @@ def _scatter_min_data_with_color( c=min_data.speed, cmap="jet", norm=norm, - s=5, - marker="o", + s=marker_size, + marker=marker, ) def _plot_line( axes: matplotlib.axes.Axes, ped_data: pd.DataFrame, color: str, + line_width: float, + line_alpha: float, ) -> None: """Plots a line for a single pedestrian's data. @@ -985,19 +999,23 @@ def _plot_line( ped_data: DataFrame containing a single pedestrian's distance and time data. color: Color of the line. + line_width: Width of the line. + line_alpha: Alpha of the lines. """ axes.plot( ped_data.distance, ped_data.time, color=color, - alpha=0.7, - lw=0.25, + alpha=line_alpha, + lw=line_width, ) def _plot_colored_line( axes: matplotlib.axes.Axes, ped_data: pd.DataFrame, norm: Normalize, + line_width: float, + line_alpha: float, ) -> None: """Plots a line for a single pedestrian's data. @@ -1010,6 +1028,8 @@ def _plot_colored_line( data. norm: Normalization for the colormap based on speed. cmap: The colormap to use for coloring the line based on speed. + line_width: Width of the lines. + line_alpha: Alpha of the lines. """ points = ped_data[["distance", "time"]].to_numpy() speed_id = ped_data.speed.to_numpy() @@ -1020,9 +1040,9 @@ def _plot_colored_line( ] for i in range(len(points) - 1) ] - line_collection = LineCollection(segments, cmap="jet", alpha=0.7, norm=norm) + line_collection = LineCollection(segments, cmap="jet", alpha=line_alpha, norm=norm) line_collection.set_array(speed_id) - line_collection.set_linewidth(0.5) + line_collection.set_linewidth(line_width) axes.add_collection(line_collection) def _add_colorbar(axes: matplotlib.axes.Axes, norm: Normalize) -> None: @@ -1056,6 +1076,7 @@ def _plot_with_speed_colors( axes: matplotlib.axes.Axes, time_distance: pd.DataFrame, speed: pd.DataFrame, + **kwargs: Any, ) -> None: """Plots pedestrian data with lines colored according to speed. @@ -1064,14 +1085,19 @@ def _plot_with_speed_colors( time_distance: DataFrame containing the pedestrian data. speed: DataFrame containing speed calculations. frame_rate: Frame rate used to adjust time values. + **kwargs: Additional customization options (line_width, line_alpha, marker_size, marker). """ + line_width = kwargs.pop("line_width", 0.5) + line_alpha = kwargs.pop("line_alpha", 0.7) + marker_size = kwargs.pop("marker_size", 5) + marker = kwargs.pop("marker", "o") time_distance = time_distance.merge(speed, on=[ID_COL, FRAME_COL]) norm = Normalize(vmin=time_distance.speed.min(), vmax=time_distance.speed.max()) for _, ped_data in time_distance.groupby(ID_COL): - _plot_colored_line(axes, ped_data, norm) + _plot_colored_line(axes, ped_data, norm, line_width, line_alpha) - _scatter_min_data_with_color(axes, time_distance, norm) + _scatter_min_data_with_color(axes, time_distance, norm, marker_size, marker) _add_colorbar(axes, norm) def _plot_without_colors( @@ -1085,19 +1111,23 @@ def _plot_without_colors( axes: The matplotlib axes to plot on. time_distance: DataFrame containing the pedestrian data. frame_rate: Frame rate used to adjust time values. - **kwargs: Additional customization options (line_color, marker_color). + **kwargs: Additional customization options (line_color, line_width, marker_color, marker_size, marker). """ line_color = kwargs.pop("line_color", PEDPY_GREY) + line_width = kwargs.pop("line_width", 0.5) + line_alpha = kwargs.pop("line_alpha", 0.7) marker_color = kwargs.pop("marker_color", PEDPY_GREY) + marker_size = kwargs.pop("marker_size", 5) + marker = kwargs.pop("marker", "o") for _, ped_data in time_distance.groupby(ID_COL): - _plot_line(axes, ped_data, line_color) + _plot_line(axes, ped_data, line_color, line_width, line_alpha) - _scatter_min_data(axes, time_distance, marker_color) + _scatter_min_data(axes, time_distance, marker_color, marker_size, marker) axes = axes or plt.gca() _setup_plot(axes, **kwargs) if speed is not None: - _plot_with_speed_colors(axes, time_distance, speed) + _plot_with_speed_colors(axes, time_distance, speed, **kwargs) else: _plot_without_colors(axes, time_distance, **kwargs) From fb7f93057a057e273d82c870d879f8b8cd61b63a Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 13:07:19 +0100 Subject: [PATCH 06/13] added further optins to plot_trajectories, measurement_setup and walkable_area --- pedpy/plotting/plotting.py | 62 +++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index d94563b7..c4931754 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -1228,10 +1228,14 @@ def plot_walkable_area( below for list of usable keywords Keyword Args: - line_color (optional): color of the borders - line_width (optional): line width of the borders + border_line_color (optional): color of the lines of the borders + border_line_width (optional): line width of the borders hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis + Returns: matplotlib.axes.Axes instance where the walkable area is plotted @@ -1239,24 +1243,29 @@ def plot_walkable_area( if axes is None: axes = plt.gca() - line_color = kwargs.pop("line_color", PEDPY_GREY) - line_width = kwargs.pop("line_width", 1.0) + border_line_color = kwargs.pop("border_line_color", PEDPY_GREY) + border_line_width = kwargs.pop("border_line_width", 1.0) hole_color = kwargs.pop("hole_color", "lightgrey") hole_alpha = kwargs.pop("hole_alpha", 1.0) + title = kwargs.pop("title", "") + x_label = kwargs.pop("x_label", r"x / m") + y_label = kwargs.pop("y_label", r"y / m") + axes = _plot_polygon( polygon=walkable_area.polygon, polygon_color="none", - line_color=line_color, - line_width=line_width, + line_color=border_line_color, + line_width=border_line_width, hole_color=hole_color, hole_alpha=hole_alpha, axes=axes, ) - axes.set_xlabel(r"x/m") - axes.set_ylabel(r"y/m") + axes.set_title(title) + axes.set_xlabel(x_label) + axes.set_ylabel(y_label) axes.autoscale_view() @@ -1287,10 +1296,14 @@ def plot_trajectories( traj_start_marker (optional): marker to indicate the start of the trajectory traj_end_marker (optional): marker to indicate the end of the trajectory - line_color (optional): color of the borders - line_width (optional): line width of the borders + border_line_color (optional): color of the borders + border_line_width (optional): line width of the borders hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis + Returns: matplotlib.axes.Axes instance where the trajectories are plotted @@ -1302,6 +1315,10 @@ def plot_trajectories( traj_start_marker = kwargs.pop("traj_start_marker", "") traj_end_marker = kwargs.pop("traj_end_marker", "") + title = kwargs.pop("title", "") + x_label = kwargs.pop("x_label", r"x / m") + y_label = kwargs.pop("y_label", r"y / m") + if axes is None: axes = plt.gca() @@ -1329,8 +1346,9 @@ def plot_trajectories( marker=traj_end_marker, ) - axes.set_xlabel(r"x/m") - axes.set_ylabel(r"y/m") + axes.set_title(title) + axes.set_xlabel(x_label) + axes.set_ylabel(y_label) return axes @@ -1372,10 +1390,13 @@ def plot_measurement_setup( trajectory traj_end_marker (optional): marker to indicate the end of the trajectory - line_color (optional): color of the borders - line_width (optional): line width of the borders - hole_color (optional): background color of holes - hole_alpha (optional): alpha of background color for holes + border_line_color (optional): color of the lines of the borders + border_line_width (optional): line width of the lines of the borders + hole_color (optional): background color of holes/geometries + hole_alpha (optional): alpha of background color for holes/geometries + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis Returns: matplotlib.axes.Axes instance where the measurement setup is plotted @@ -1388,6 +1409,10 @@ def plot_measurement_setup( ml_color = kwargs.pop("ml_color", PEDPY_BLUE) ml_width = kwargs.pop("ml_width", 1.0) + title = kwargs.pop("title", "") + x_label = kwargs.pop("x_label", r"x / m") + y_label = kwargs.pop("y_label", r"y / m") + if axes is None: axes = plt.gca() @@ -1412,8 +1437,9 @@ def plot_measurement_setup( for measurement_line in measurement_lines: axes.plot(*measurement_line.xy, color=ml_color, linewidth=ml_width) - axes.set_xlabel(r"x / m") - axes.set_ylabel(r"y / m") + axes.set_title(title) + axes.set_xlabel(x_label) + axes.set_ylabel(y_label) return axes From 67a37dfd722fbc843d8cb3babbc54033ec3669fb Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 14:17:27 +0100 Subject: [PATCH 07/13] added options in plot_neighborhood and changed options in _plot_polygon --- pedpy/plotting/plotting.py | 44 ++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index c4931754..2c063b87 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -66,11 +66,9 @@ def _plot_polygon( polygon: shapely.Polygon, polygon_color: Any, polygon_alpha: float = 1, - line_color: Any = PEDPY_GREY, - line_width: float = 1, - hole_color: Any = "lightgrey", hole_alpha: float = 1, zorder: float = 1000, + **kwargs: Any, ) -> matplotlib.axes.Axes: """Plot the shapely polygon (including holes). @@ -80,13 +78,19 @@ def _plot_polygon( created polygon_color (Any): background color of the polygon polygon_alpha (float): alpha of the background for the polygon - line_color (Any): color of the borders - line_width (float): line width of the borders - hole_color (Any): background color of holes hole_alpha (float): alpha of background color for holes zorder (float): Specifies the drawing order of the polygon, lower values are drawn first + kwargs: Additional parameters to change the plot appearance, see + below for list of usable keywords + + Keyword Args: + line_color (optional, Any): color of the borders + line_width (optional, float): line width of the borders + hole_color (optional, Any): background color of holes + + Returns: matplotlib.axes.Axes instance where the polygon is plotted @@ -94,6 +98,10 @@ def _plot_polygon( # Plot the boundary of the polygon/holes separately to get the same color # as the outside as alpha modifies all colors + line_color = kwargs.pop("line_color", PEDPY_GREY) + line_width = kwargs.pop("line_width", 1) + hole_color = kwargs.pop("hole_color", "lightgrey") + # Plot the exterior of the polygon exterior_coords = list(polygon.exterior.coords) @@ -739,10 +747,14 @@ def plot_neighborhood( default_color (optional): color of default pedestrians, which are not neighbors of the base pedestrian default_alpha (optional): alpha of the default pedestrians - line_color (optional): color of the borders - line_width (optional): line width of the borders + border_line_color (optional): color of the borders + border_line_width (optional): line width of the borders hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis + Returns: matplotlib.axes.Axes: instances where the neighborhood is plotted @@ -803,10 +815,13 @@ def _plot_neighborhood( default_color (optional): color of default pedestrians, which are not neighbors of the base pedestrian default_alpha (optional): alpha of the default pedestrians - line_color (optional): color of the borders - line_width (optional): line width of the borders + border_line_color (optional): color of the borders + border_line_width (optional): line width of the borders hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis Returns: matplotlib.axes.Axes: instances where the neighborhood is plotted @@ -819,6 +834,9 @@ def _plot_neighborhood( default_color = to_rgb(kwargs.pop("default_color", PEDPY_GREY)) default_alpha = kwargs.pop("default_alpha", 0.2) + x_label = kwargs.pop("x_label", r"x / m") + y_label = kwargs.pop("y_label", r"y / m") + # Filter voronoi_data for polygons in the same frame voronoi_neighbors = voronoi_data[voronoi_data[FRAME_COL] == frame] @@ -840,7 +858,6 @@ def _plot_neighborhood( # Set up the plot if axes is None: axes = plt.gca() - axes.set_title(f"Neighbors of pedestrian {pedestrian_id}") # Plot the walkable area if walkable_area is not None: @@ -875,6 +892,11 @@ def _plot_neighborhood( # Set aspect ratio axes.set_aspect("equal") + title = kwargs.pop("title", "Neighbors of pedestrian {}".format(pedestrian_id)) + axes.set_title(title) + axes.set_xlabel(x_label) + axes.set_ylabel(y_label) + return axes From ebe9049eb6a4faa0c50fc1a727de6353b1b66d36 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 15:19:06 +0100 Subject: [PATCH 08/13] add further options to plot_voronoi_cells --- pedpy/plotting/plotting.py | 46 +++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 2c063b87..935e6b35 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -1493,22 +1493,29 @@ def plot_voronoi_cells( # noqa: PLR0912,PLR0915 below for list of usable keywords Keyword Args: + title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis ped_color (optional): color used to display current ped positions + ped_size (optional): size of the marker of the current ped positions voronoi_border_color (optional): border color of Voronoi cells + voronoi_border_width (optional): border width of the Voronoi cells voronoi_inside_ma_alpha (optional): alpha of part of Voronoi cell inside the measurement area, data needs to contain column "intersection"! voronoi_outside_ma_alpha (optional): alpha of part of Voronoi cell outside the measurement area - color_by_column (str, optional): Optioanlly provide a column name to + color_by_column (str, optional): Optionally provide a column name to specify the data to color the cell. Only supports Integer and Float data types. E.g. color_by_column `DENSITY_COL` vmin (optional): vmin of colormap, only used when color_mode != "id" vmax (optional): vmax of colormap, only used when color_mode != "id" + cmap (optional): colormap used for show_colorbar (optional): colorbar is displayed, only used when color_mode != "id" cb_location (optional): location of the colorbar, only used when color_mode != "id" + cb_label (optional): label of colorbar ma_line_color (optional): color of the measurement areas borders ma_line_width (optional): line width of the measurement areas borders ma_color (optional): fill color of the measurement areas @@ -1519,13 +1526,18 @@ def plot_voronoi_cells( # noqa: PLR0912,PLR0915 line_width (optional): line width of the borders hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes - cmap (optional): colormap used for + Returns: matplotlib.axes.Axes instance where the Voronoi cells are plotted """ + title = kwargs.pop("title", "") + x_label = kwargs.pop("x_label", r"x / m") + y_label = kwargs.pop("y_label", r"y / m") + ped_color = kwargs.pop("ped_color", PEDPY_BLUE) ped_size = kwargs.pop("ped_size", 5) voronoi_border_color = kwargs.pop("voronoi_border_color", PEDPY_BLUE) + voronoi_border_width = kwargs.pop("voronoi_border_width", 1) voronoi_inside_ma_alpha = kwargs.pop("voronoi_inside_ma_alpha", 1) voronoi_outside_ma_alpha = kwargs.pop("voronoi_outside_ma_alpha", 1) @@ -1533,6 +1545,7 @@ def plot_voronoi_cells( # noqa: PLR0912,PLR0915 vmax = kwargs.pop("vmax", None) cb_location = kwargs.pop("cb_location", "right") show_colorbar = kwargs.pop("show_colorbar", True) + cb_label = kwargs.pop("cb_label", None) color_by_column = kwargs.pop("color_by_column", None) voronoi_colormap = plt.get_cmap(kwargs.pop("cmap", "YlGn")) @@ -1588,6 +1601,7 @@ def inverse(values): axes=axes, polygon=poly, line_color=voronoi_border_color, + line_width=voronoi_border_width, polygon_color=color, polygon_alpha=voronoi_outside_ma_alpha, zorder=1, @@ -1608,15 +1622,20 @@ def inverse(values): if traj_data: axes.scatter(row[X_COL], row[Y_COL], color=ped_color, s=ped_size) - if show_colorbar and color_by_column and typ == "float64": - if color_by_column == DENSITY_COL: - label = "$\\rho$ / $\\frac{1}{m^2}$" - elif color_by_column == SPEED_COL: - label = r"v / $\frac{m}{s}$" - elif color_by_column == ID_COL: - label = "Id" - else: - label = "" + if show_colorbar: + if color_by_column and typ == "float64": + if color_by_column == DENSITY_COL: + label = "$\\rho$ / $\\frac{1}{m^2}$" + elif color_by_column == SPEED_COL: + label = r"v / $\frac{m}{s}$" + elif color_by_column == ID_COL: + label = "Id" + else: + label = " " + + if cb_label is not None: + label = cb_label + plt.colorbar( scalar_mappable, ax=axes, @@ -1627,6 +1646,7 @@ def inverse(values): if walkable_area is not None: plot_walkable_area(axes=axes, walkable_area=walkable_area, **kwargs) - axes.set_xlabel(r"x / m") - axes.set_ylabel(r"y / m") + axes.set_title(title) + axes.set_xlabel(x_label) + axes.set_ylabel(y_label) return axes From 1435a7b93ec644259ca435ab39cbd9fc13087d83 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 15:36:46 +0100 Subject: [PATCH 09/13] adjustet plot_profiles and plot_voronoi-cells --- pedpy/plotting/plotting.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 935e6b35..2f7351a8 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -1181,6 +1181,8 @@ def plot_profiles( Keyword Args: title (optional): title of the plot + x_label (optional): label on the x-axis + y_label (optional): label on the y-axis walkable_color (optional): color of the walkable area in the plot hole_color (optional): background color of holes hole_alpha (optional): alpha of background color for holes From 808ee39c43b5314f3c5ed1cb8bfc24757b652d25 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 5 Dec 2025 16:19:02 +0100 Subject: [PATCH 10/13] update user_guide notebook according to use the adjsuted plot_functions --- notebooks/user_guide.ipynb | 230 ++++++++++++++++--------------------- 1 file changed, 98 insertions(+), 132 deletions(-) diff --git a/notebooks/user_guide.ipynb b/notebooks/user_guide.ipynb index 2fcb4717..f9d2162d 100644 --- a/notebooks/user_guide.ipynb +++ b/notebooks/user_guide.ipynb @@ -1641,21 +1641,20 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_GREEN\n", + "from pedpy import PEDPY_GREEN, plot_speed\n", "\n", "ped_id = 25\n", "\n", "plt.figure()\n", - "plt.title(f\"Speed time-series of a pedestrian {ped_id} (border excluded)\")\n", + "title = \"Speed time-series of a pedestrian {} (border excluded)\".format(ped_id)\n", "single_individual_speed = individual_speed_exclude[individual_speed_exclude.id == ped_id]\n", - "plt.plot(\n", - " single_individual_speed.frame,\n", - " single_individual_speed.speed,\n", + "\n", + "plot_speed(\n", + " speed=single_individual_speed,\n", " color=PEDPY_GREEN,\n", + " title=title,\n", ")\n", "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"v / m/s\")\n", "plt.show()" ] }, @@ -1720,19 +1719,13 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_RED\n", + "from pedpy import PEDPY_RED, plot_speed\n", "\n", "plt.figure()\n", - "plt.title(f\"Speed time-series of an pedestrian {ped_id} (adaptive)\")\n", + "title = f\"Speed time-series of an pedestrian {ped_id} (adaptive)\"\n", "single_individual_speed = individual_speed_adaptive[individual_speed_adaptive.id == ped_id]\n", - "plt.plot(\n", - " single_individual_speed.frame,\n", - " single_individual_speed.speed,\n", - " color=PEDPY_RED,\n", - ")\n", + "plot_speed(speed=single_individual_speed, color=PEDPY_RED, title=title)\n", "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"v / m/s\")\n", "plt.show()" ] }, @@ -1801,19 +1794,17 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_GREY\n", + "from pedpy import PEDPY_GREY, plot_speed\n", "\n", "plt.figure()\n", - "plt.title(f\"Speed time-series of an pedestrian {ped_id} (single sided)\")\n", + "title = f\"Speed time-series of an pedestrian {ped_id} (single sided)\"\n", "single_individual_speed = individual_speed_single_sided[individual_speed_single_sided.id == ped_id]\n", - "plt.plot(\n", - " single_individual_speed.frame,\n", - " single_individual_speed.speed,\n", + "plot_speed(\n", + " speed=single_individual_speed,\n", " color=PEDPY_GREY,\n", + " title=title,\n", ")\n", "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"v / m/s\")\n", "plt.show()" ] }, @@ -1833,14 +1824,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "jupyter": { - "outputs_hidden": false - }, - "tags": [ - "hide-input" - ] - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -1854,71 +1838,67 @@ "speed_adaptive = individual_speed_adaptive[individual_speed_adaptive.id == ped_id]\n", "speed_single_sided = individual_speed_single_sided[individual_speed_single_sided.id == ped_id]\n", "\n", - "ax[0].plot(\n", - " speed_single_sided.frame,\n", - " speed_single_sided.speed,\n", + "plot_speed(\n", + " axes=ax[0],\n", + " speed=speed_single_sided,\n", " color=PEDPY_GREY,\n", - " linewidth=3,\n", + " line_width=3,\n", " label=\"single sided\",\n", ")\n", - "ax[0].plot(\n", - " speed_adaptive.frame,\n", - " speed_adaptive.speed,\n", + "plot_speed(\n", + " axes=ax[0],\n", + " speed=speed_adaptive,\n", " color=PEDPY_RED,\n", - " linewidth=3,\n", + " line_width=3,\n", " label=\"adaptive\",\n", ")\n", - "ax[0].plot(\n", - " speed_exclude.frame,\n", - " speed_exclude.speed,\n", + "plot_speed(\n", + " axes=ax[0],\n", + " speed=speed_exclude,\n", " color=PEDPY_GREEN,\n", - " linewidth=3,\n", + " line_width=3,\n", " label=\"excluded\",\n", ")\n", - "ax[0].set_xlabel(\"frame\")\n", - "ax[0].set_ylabel(\"v / m/s\")\n", "ax[0].legend()\n", "\n", - "ax[1].plot(\n", - " speed_single_sided.frame[speed_single_sided.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", - " speed_single_sided.speed[speed_single_sided.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[1],\n", + " speed=speed_single_sided[speed_single_sided.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", " color=PEDPY_GREY,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", - "ax[1].plot(\n", - " speed_adaptive.frame[speed_adaptive.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", - " speed_adaptive.speed[speed_adaptive.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[1],\n", + " speed=speed_adaptive[speed_adaptive.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", " color=PEDPY_RED,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", - "ax[1].plot(\n", - " speed_exclude.frame[speed_exclude.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", - " speed_exclude.speed[speed_exclude.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[1],\n", + " speed=speed_exclude[speed_exclude.frame < speed_single_sided.frame.min() + 3 * frame_step],\n", " color=PEDPY_GREEN,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", - "ax[1].set_xlabel(\"frame\")\n", "\n", - "ax[2].plot(\n", - " speed_single_sided.frame[speed_single_sided.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", - " speed_single_sided.speed[speed_single_sided.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[2],\n", + " speed=speed_single_sided[speed_single_sided.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", " color=PEDPY_GREY,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", - "ax[2].plot(\n", - " speed_adaptive.frame[speed_adaptive.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", - " speed_adaptive.speed[speed_adaptive.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[2],\n", + " speed=speed_adaptive[speed_adaptive.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", " color=PEDPY_RED,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", - "ax[2].plot(\n", - " speed_exclude.frame[speed_exclude.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", - " speed_exclude.speed[speed_exclude.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", + "plot_speed(\n", + " axes=ax[2],\n", + " speed=speed_exclude[speed_exclude.frame > speed_single_sided.frame.max() - 3 * frame_step],\n", " color=PEDPY_GREEN,\n", - " linewidth=3,\n", + " line_width=3,\n", ")\n", "\n", - "ax[2].set_xlabel(\"frame\")\n", "plt.show()" ] }, @@ -1979,7 +1959,7 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_BLUE, PEDPY_GREEN, PEDPY_GREY, PEDPY_RED\n", + "from pedpy import PEDPY_BLUE, PEDPY_GREEN, PEDPY_GREY, PEDPY_RED, plot_speed\n", "\n", "colors = [PEDPY_BLUE, PEDPY_GREY, PEDPY_RED, PEDPY_GREEN]\n", "ped_ids = [10, 20, 17, 70]\n", @@ -1988,14 +1968,13 @@ "plt.title(\"Velocity time-series of an excerpt of the pedestrians in a specific direction\")\n", "for color, ped_id in zip(colors, ped_ids, strict=False):\n", " single_individual_speed = individual_speed_direction[individual_speed_direction.id == ped_id]\n", - " plt.plot(\n", - " single_individual_speed.frame,\n", - " single_individual_speed.speed,\n", + " plot_speed(\n", + " speed=single_individual_speed,\n", " color=color,\n", + " label=\"Ped ID {}\".format(ped_id),\n", " )\n", "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"v / m/s\")\n", + "plt.legend()\n", "plt.show()" ] }, @@ -2065,7 +2044,7 @@ "from pedpy import PEDPY_BLUE, plot_speed\n", "\n", "plot_speed(\n", - " speed=mean_speed.speed,\n", + " speed=mean_speed,\n", " title=\"Mean speed in front of the bottleneck\",\n", " color=PEDPY_BLUE,\n", ")\n", @@ -2114,7 +2093,7 @@ "from pedpy import PEDPY_RED, plot_speed\n", "\n", "plot_speed(\n", - " speed=mean_speed_direction.speed,\n", + " speed=mean_speed_direction,\n", " title=\"Mean speed in specific direction in front of the bottleneck\",\n", " color=PEDPY_RED,\n", ")\n", @@ -2195,7 +2174,7 @@ "from pedpy import PEDPY_ORANGE, plot_speed\n", "\n", "plot_speed(\n", - " speed=voronoi_speed.speed,\n", + " speed=voronoi_speed,\n", " title=\"Voronoi speed in front of the bottleneck\",\n", " color=PEDPY_ORANGE,\n", ")\n", @@ -2245,7 +2224,7 @@ "from pedpy import PEDPY_GREY, plot_speed\n", "\n", "plot_speed(\n", - " speed=voronoi_speed.speed,\n", + " speed=voronoi_speed,\n", " title=\"Voronoi velocity in specific direction in front of the bottleneck\",\n", " color=PEDPY_GREY,\n", ")\n", @@ -2277,36 +2256,30 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_BLUE, PEDPY_GREY, PEDPY_ORANGE, PEDPY_RED\n", + "from pedpy import PEDPY_BLUE, PEDPY_GREY, PEDPY_ORANGE, PEDPY_RED, plot_speed\n", "\n", "plt.figure(figsize=(8, 6))\n", "plt.title(\"Comparison of different speed methods\")\n", - "plt.plot(\n", - " voronoi_speed.frame,\n", - " voronoi_speed.speed,\n", + "plot_speed(\n", + " speed=voronoi_speed,\n", " label=\"Voronoi\",\n", " color=PEDPY_ORANGE,\n", ")\n", - "plt.plot(\n", - " voronoi_speed_direction.frame,\n", - " voronoi_speed_direction.speed,\n", + "plot_speed(\n", + " speed=voronoi_speed_direction,\n", " label=\"Voronoi direction\",\n", " color=PEDPY_GREY,\n", ")\n", - "plt.plot(\n", - " mean_speed.frame,\n", - " mean_speed.speed,\n", + "plot_speed(\n", + " speed=mean_speed,\n", " label=\"classic\",\n", " color=PEDPY_BLUE,\n", ")\n", - "plt.plot(\n", - " mean_speed_direction.frame,\n", - " mean_speed_direction.speed,\n", + "plot_speed(\n", + " speed=mean_speed_direction,\n", " label=\"classic direction\",\n", " color=PEDPY_RED,\n", ")\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"v / m/s\")\n", "plt.legend()\n", "plt.grid()\n", "plt.show()" @@ -2365,7 +2338,9 @@ "from pedpy import plot_speed\n", "from pedpy.column_identifier import SPEED_COL\n", "\n", - "plot_speed(speed=line_speed[SPEED_COL])\n", + "plot_speed(\n", + " speed=line_speed,\n", + ")\n", "plt.show()" ] }, @@ -2503,9 +2478,9 @@ } }, "source": [ - "#### Flow at bottleneck\n", + "#### Flow at measurement line\n", "\n", - "From the N-t data we then can compute the flow at the bottleneck.\n", + "From the N-t data we then can compute the flow measured at a measurement line (inside the bottleneck).\n", "\n", "For the computation of the flow we look at frame intervals $\\Delta frame$ in which the flow is computed.\n", "The first intervals starts, when the first person crossed the {class}`measurement line `.\n", @@ -2588,9 +2563,9 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import plot_flow\n", + "from pedpy import plot_crossing_speed_flow\n", "\n", - "plot_flow(\n", + "plot_crossing_speed_flow(\n", " flow=flow,\n", " title=\"Crossing velocities at the corresponding flow at bottleneck\",\n", ")\n", @@ -2708,21 +2683,19 @@ "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_GREEN\n", + "from pedpy import PEDPY_GREEN, plot_acceleration\n", "\n", "ped_id = 50\n", "\n", "plt.figure()\n", - "plt.title(f\"Acceleration time-series of a pedestrian {ped_id} (border excluded)\")\n", + "title = f\"Acceleration time-series of a pedestrian {ped_id} (border excluded)\"\n", "single_individual_acceleration = individual_acceleration_exclude[individual_acceleration_exclude.id == ped_id]\n", - "plt.plot(\n", - " single_individual_acceleration.frame,\n", - " single_individual_acceleration.acceleration,\n", + "plot_acceleration(\n", + " acceleration=single_individual_acceleration,\n", " color=PEDPY_GREEN,\n", + " title=title,\n", ")\n", "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"a / $m/s^2$\")\n", "plt.show()" ] }, @@ -2780,14 +2753,13 @@ "plt.title(\"Acceleration time-series of an excerpt of the pedestrians in a specific direction\")\n", "for color, ped_id in zip(colors, ped_ids, strict=False):\n", " single_individual_acceleration = individual_acceleration_direction[individual_acceleration_direction.id == ped_id]\n", - " plt.plot(\n", - " single_individual_acceleration.frame,\n", - " single_individual_acceleration.acceleration,\n", + " label = \"Ped ID \".format(ped_id)\n", + " plot_acceleration(\n", + " acceleration=single_individual_acceleration,\n", " color=color,\n", + " label=label,\n", " )\n", - "\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"a / $m/s^2$\")\n", + "plt.legend()\n", "plt.show()" ] }, @@ -2877,7 +2849,7 @@ "from pedpy import PEDPY_BLUE, plot_acceleration\n", "\n", "plot_acceleration(\n", - " acceleration=mean_acceleration.acceleration,\n", + " acceleration=mean_acceleration,\n", " title=\"Mean acceleration in front of the bottleneck\",\n", " color=PEDPY_BLUE,\n", ")\n", @@ -2919,7 +2891,7 @@ "from pedpy import PEDPY_RED, plot_acceleration\n", "\n", "plot_acceleration(\n", - " acceleration=mean_acceleration_direction.acceleration,\n", + " acceleration=mean_acceleration_direction,\n", " title=\"Mean acceleration in specific direction in front of the bottleneck\",\n", " color=PEDPY_RED,\n", ")\n", @@ -3016,7 +2988,7 @@ "from pedpy import PEDPY_ORANGE, plot_acceleration\n", "\n", "plot_acceleration(\n", - " acceleration=voronoi_acceleration.acceleration,\n", + " acceleration=voronoi_acceleration,\n", " title=\"Voronoi acceleration in front of the bottleneck\",\n", " color=PEDPY_ORANGE,\n", ")\n", @@ -3059,7 +3031,7 @@ "from pedpy import PEDPY_GREY, plot_acceleration\n", "\n", "plot_acceleration(\n", - " acceleration=voronoi_acceleration.acceleration,\n", + " acceleration=voronoi_acceleration,\n", " title=\"Voronoi acceleration in specific direction in front of the bottleneck\",\n", " color=PEDPY_GREY,\n", ")\n", @@ -3091,32 +3063,26 @@ "\n", "plt.figure(figsize=(8, 6))\n", "plt.title(\"Comparison of different acceleration methods\")\n", - "plt.plot(\n", - " voronoi_acceleration.frame,\n", - " voronoi_acceleration.acceleration,\n", + "plot_acceleration(\n", + " acceleration=voronoi_acceleration,\n", " label=\"Voronoi\",\n", " color=PEDPY_ORANGE,\n", ")\n", - "plt.plot(\n", - " voronoi_acceleration_direction.frame,\n", - " voronoi_acceleration_direction.acceleration,\n", + "plot_acceleration(\n", + " acceleration=voronoi_acceleration_direction,\n", " label=\"Voronoi direction\",\n", " color=PEDPY_GREY,\n", ")\n", - "plt.plot(\n", - " mean_acceleration.frame,\n", - " mean_acceleration.acceleration,\n", + "plot_acceleration(\n", + " acceleration=mean_acceleration,\n", " label=\"classic\",\n", " color=PEDPY_BLUE,\n", ")\n", - "plt.plot(\n", - " mean_acceleration_direction.frame,\n", - " mean_acceleration_direction.acceleration,\n", + "plot_acceleration(\n", + " acceleration=mean_acceleration_direction,\n", " label=\"classic direction\",\n", " color=PEDPY_RED,\n", ")\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"a / $m/s^2$\")\n", "plt.legend()\n", "plt.grid()\n", "plt.show()" From d88295d7571459c4840a073a62d5db97442bbb1d Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Thu, 11 Dec 2025 15:32:59 +0100 Subject: [PATCH 11/13] added option to plot time at x-axis for all timeseries plot_functions --- pedpy/plotting/plotting.py | 144 +++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 15 deletions(-) diff --git a/pedpy/plotting/plotting.py b/pedpy/plotting/plotting.py index 2f7351a8..1b0ff3e1 100644 --- a/pedpy/plotting/plotting.py +++ b/pedpy/plotting/plotting.py @@ -220,6 +220,8 @@ def plot_speed_at_line( line_width (optional): line width of the density timeseries x_label (optional): label on the x-axis y_label (optional): label on the y-axis + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' Returns: @@ -232,17 +234,34 @@ def plot_speed_at_line( color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) title = kwargs.get("title", "") - x_label = kwargs.get("x_label", "Frame") + x_axis = kwargs.get("x_axis", "frame") y_label = kwargs.get("y_label", "v / m/s") - label_sp1 = kwargs.get("lable_species1", "species 1") - label_sp2 = kwargs.get("lable_species2", "species 2") - label_total = kwargs.get("lable_total", "total") + label_sp1 = kwargs.get("label_species1", "species 1") + label_sp2 = kwargs.get("label_species2", "species 2") + label_total = kwargs.get("label_total", "total") line_width = kwargs.get("line_width", 1.5) + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in speed_at_line.columns: + x = speed_at_line[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = speed_at_line[FRAME_COL] + x_label = "frame" + else: + x = speed_at_line[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = speed_at_line[FRAME_COL] + return _plot_multiple_series( axes=axes, title=title, - x=speed_at_line[FRAME_COL], + x=x, y_s=[ speed_at_line[SPEED_SP1_COL], speed_at_line[SPEED_SP2_COL], @@ -283,6 +302,8 @@ def plot_density_at_line( line_width (optional): line width of the density timeseries x_label (optional): label on the x-axis y_label (optional): label on the y-axis + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' Returns: matplotlib.axes.Axes instance where the densities are plotted @@ -294,17 +315,34 @@ def plot_density_at_line( color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) title = kwargs.get("title", "") - x_label = kwargs.get("x_label", "Frame") + x_axis = kwargs.pop("x_axis", "frame") y_label = kwargs.get("y_label", "$\\rho$ / 1/$m^2$") label_sp1 = kwargs.get("label_species1", "species 1") label_sp2 = kwargs.get("label_species2", "species 2") label_total = kwargs.get("label_total", "total") line_width = kwargs.get("line_width", 1.5) + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in density_at_line.columns: + x = density_at_line[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = density_at_line[FRAME_COL] + x_label = "frame" + else: + x = density_at_line[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = density_at_line[FRAME_COL] + return _plot_multiple_series( axes=axes, title=title, - x=density_at_line[FRAME_COL], + x=x, y_s=[ density_at_line[DENSITY_SP1_COL], density_at_line[DENSITY_SP2_COL], @@ -345,6 +383,8 @@ def plot_flow_at_line( line_width (optional): line width of the density timeseries x_label (optional): label on the x-axis y_label (optional): label on the y-axis + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' Returns: matplotlib.axes.Axes instance where the profiles are plotted @@ -356,17 +396,34 @@ def plot_flow_at_line( color_sp2 = kwargs.get("color_species2", PEDPY_ORANGE) color_total = kwargs.get("color_total", PEDPY_GREEN) title = kwargs.get("title", "") - x_label = kwargs.get("x_label", "Frame") + x_axis = kwargs.pop("x_axis", "frame") y_label = kwargs.get("y_label", "J / 1/s") label_sp1 = kwargs.get("lable_species1", "species 1") label_sp2 = kwargs.get("lable_species2", "species 2") label_total = kwargs.get("lable_total", "total") line_width = kwargs.get("line_width", 1.5) + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in flow_at_line.columns: + x = flow_at_line[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = flow_at_line[FRAME_COL] + x_label = "frame" + else: + x = flow_at_line[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = flow_at_line[FRAME_COL] + return _plot_multiple_series( axes=axes, title=title, - x=flow_at_line[FRAME_COL], + x=x, y_s=[ flow_at_line[FLOW_SP1_COL], flow_at_line[FLOW_SP2_COL], @@ -444,6 +501,8 @@ def plot_density( Keyword Args: color (optional): color of the plot title (optional): title of the plot + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' line_width (optional): line width of the density timeseries x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -457,13 +516,30 @@ def plot_density( color = kwargs.pop("color", PEDPY_BLUE) line_width = kwargs.pop("line_width", 1.5) title = kwargs.pop("title", "") - x_label = kwargs.pop("x_label", "frame") + x_axis = kwargs.pop("x_axis", "frame") y_label = kwargs.pop("y_label", "$\\rho$ / 1/$m^2$") + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in density.columns: + x = density[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = density[FRAME_COL] + x_label = "frame" + else: + x = density[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = density[FRAME_COL] + return _plot_series( axes=axes, title=title, - x=density[FRAME_COL], + x=x, y=density[DENSITY_COL], color=color, line_width=line_width, @@ -492,6 +568,8 @@ def plot_speed( color (optional): color of the plot line_width (optional): line width of the speed timeseries title (optional): title of the plot + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -504,13 +582,30 @@ def plot_speed( color = kwargs.pop("color", PEDPY_BLUE) line_width = kwargs.pop("line_width", 1.5) title = kwargs.pop("title", "") - x_label = kwargs.pop("x_label", "frame") + x_axis = kwargs.pop("x_axis", "frame") y_label = kwargs.pop("y_label", "v / m/s") + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in speed.columns: + x = speed[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = speed[FRAME_COL] + x_label = "frame" + else: + x = speed[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = speed[FRAME_COL] + return _plot_series( axes=axes, title=title, - x=speed[FRAME_COL], + x=x, y=speed[SPEED_COL], color=color, line_width=line_width, @@ -680,6 +775,8 @@ def plot_acceleration( color (optional): color of the plot line_width (optional): line width of the acceleration time series title (optional): title of the plot + x_axis (optional): chose whether the 'frame' (default) or 'time' is plotted on the x-axis + framerate (optional): give the framerate, when x-axis=='time' x_label (optional): label on the x-axis y_label (optional): label on the y-axis @@ -692,13 +789,30 @@ def plot_acceleration( color = kwargs.pop("color", PEDPY_BLUE) line_width = kwargs.pop("line_width", 1.5) title = kwargs.pop("title", "") - x_label = kwargs.pop("x_label", "frame") + x_axis = kwargs.pop("x_axis", "frame") y_label = kwargs.pop("y_label", "a / $m/s^2$") + if x_axis == "time": + x_label = kwargs.pop("x_label", "time / $s$") + if TIME_COL in acceleration.columns: + x = acceleration[TIME_COL] + else: + framerate = kwargs.pop("framerate", 1) + if framerate == 1: + title = "Attention: no framerate was available to calculate time from frame!" + x = acceleration[FRAME_COL] + x_label = "frame" + else: + x = acceleration[FRAME_COL] / framerate + + else: + x_label = kwargs.pop("x_label", "frame") + x = acceleration[FRAME_COL] + return _plot_series( axes=axes, title=title, - x=acceleration[FRAME_COL], + x=x, y=acceleration[ACC_COL], color=color, line_width=line_width, From adb856fc47abce365c164374d65f676f37b6df87 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Thu, 11 Dec 2025 16:12:56 +0100 Subject: [PATCH 12/13] adjusted the user_guide notebook to the changes made in the plot_functions --- notebooks/user_guide.ipynb | 94 +++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/notebooks/user_guide.ipynb b/notebooks/user_guide.ipynb index f9d2162d..4bb611c4 100644 --- a/notebooks/user_guide.ipynb +++ b/notebooks/user_guide.ipynb @@ -985,6 +985,34 @@ "plt.show()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Note:\n", + "\n", + "For all functions that plot time series, it is also possible to plot the time in Seconds on the x-axis instead of the frame. You can choose this option with the keyword argument x_axis. Then, also a framerate needs to be defined as in the following example:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matplotlib.pyplot as plt\n", + "\n", + "from pedpy import plot_density\n", + "\n", + "plot_density(\n", + " density=classic_density,\n", + " title=\"Classic density\",\n", + " x_axis=\"time\",\n", + " framerate=traj.frame_rate,\n", + ")\n", + "plt.show()" + ] + }, { "cell_type": "markdown", "metadata": { @@ -1020,6 +1048,13 @@ "The computation of the individual polygons can be done from the {class}`trajectory data` and {class}`walkable area ` with:" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -1292,42 +1327,29 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "jupyter": { - "outputs_hidden": false - }, - "tags": [ - "hide-input" - ] - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "\n", - "from pedpy import PEDPY_BLUE, PEDPY_GREY, PEDPY_ORANGE\n", + "from pedpy import PEDPY_BLUE, PEDPY_GREY, PEDPY_ORANGE, plot_density\n", "\n", "fig = plt.figure()\n", - "plt.title(\"Comparison of different density methods\")\n", - "plt.plot(\n", - " classic_density.frame,\n", - " classic_density.density,\n", + "plot_density(\n", + " density=classic_density,\n", " label=\"classic\",\n", " color=PEDPY_BLUE,\n", ")\n", - "plt.plot(\n", - " density_voronoi.frame,\n", - " density_voronoi.density,\n", + "plot_density(\n", + " density=density_voronoi,\n", " label=\"voronoi\",\n", " color=PEDPY_ORANGE,\n", ")\n", - "plt.plot(\n", - " density_voronoi_cutoff.frame,\n", - " density_voronoi_cutoff.density,\n", + "plot_density(\n", + " density=density_voronoi_cutoff,\n", " label=\"voronoi with cutoff\",\n", " color=PEDPY_GREY,\n", ")\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"$\\\\rho$ / 1/$m^2$\")\n", "plt.grid()\n", "plt.legend()\n", "plt.show()" @@ -1335,11 +1357,7 @@ }, { "cell_type": "markdown", - "metadata": { - "jupyter": { - "outputs_hidden": false - } - }, + "metadata": {}, "source": [ "(passing_density)=\n", " #### Passing density (individual)\n", @@ -1544,7 +1562,9 @@ "metadata": {}, "outputs": [], "source": [ - "plot_density(density=line_density, title=\"density at measurement line\")\n", + "from pedpy import plot_density_at_line\n", + "\n", + "plot_density_at_line(density_at_line=line_density, title=\"Density at measurement line\")\n", "plt.show()" ] }, @@ -2259,7 +2279,6 @@ "from pedpy import PEDPY_BLUE, PEDPY_GREY, PEDPY_ORANGE, PEDPY_RED, plot_speed\n", "\n", "plt.figure(figsize=(8, 6))\n", - "plt.title(\"Comparison of different speed methods\")\n", "plot_speed(\n", " speed=voronoi_speed,\n", " label=\"Voronoi\",\n", @@ -2280,6 +2299,7 @@ " label=\"classic direction\",\n", " color=PEDPY_RED,\n", ")\n", + "plt.title(\"Comparison of different speed methods\")\n", "plt.legend()\n", "plt.grid()\n", "plt.show()" @@ -2335,11 +2355,11 @@ }, "outputs": [], "source": [ - "from pedpy import plot_speed\n", - "from pedpy.column_identifier import SPEED_COL\n", + "from pedpy import plot_speed_at_line\n", "\n", - "plot_speed(\n", - " speed=line_speed,\n", + "plot_speed_at_line(\n", + " speed_at_line=line_speed,\n", + " title=\"Speed at measurement line\",\n", ")\n", "plt.show()" ] @@ -3138,12 +3158,12 @@ }, "outputs": [], "source": [ - "from pedpy.column_identifier import FLOW_COL\n", + "import matplotlib.pyplot as plt\n", + "\n", + "from pedpy import plot_flow_at_line\n", "\n", - "plt.plot(line_flow[FRAME_COL], line_flow[FLOW_COL])\n", - "plt.title(\"flow on line\")\n", - "plt.xlabel(\"frame\")\n", - "plt.ylabel(\"$J$\")\n", + "fig = plt.figure()\n", + "plot_flow_at_line(flow_at_line=line_flow, title=\"Flow at line\")\n", "plt.show()" ] }, From 72fe61582b2dc4e79aedb7d4c8e0700acfdc8712 Mon Sep 17 00:00:00 2001 From: JuleAdrian Date: Fri, 12 Dec 2025 10:42:47 +0100 Subject: [PATCH 13/13] adjusted the fundamental_diagram notebook to deal with the changed plot_functions --- notebooks/fundamental_diagram.ipynb | 88 +++++++++++++---------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/notebooks/fundamental_diagram.ipynb b/notebooks/fundamental_diagram.ipynb index 9f1e03c4..33b7813a 100644 --- a/notebooks/fundamental_diagram.ipynb +++ b/notebooks/fundamental_diagram.ipynb @@ -245,6 +245,15 @@ " nts[name] = nt" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "len(nts)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -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", @@ -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", @@ -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()" ] }, { @@ -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", @@ -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()" ] }, @@ -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", @@ -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", @@ -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", @@ -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()" ]