Skip to content

Commit 93450f0

Browse files
committed
Add marker customization to plot_trajectories
Allow independent control of start, end, and frame markers: - traj_start/end_color: marker color (default: traj_color) - traj_start/end_marker_size: marker size - traj_start/end_marker_alpha: marker alpha - traj_frame: int or list of frames to mark positions at - traj_frame_marker/color/size/alpha: style the frame markers Markers are now drawn with zorder=3 so they always appear on top of the trajectory lines (zorder=2).
1 parent d362055 commit 93450f0

1 file changed

Lines changed: 83 additions & 8 deletions

File tree

pedpy/plotting/plotting.py

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,14 @@ def plot_crossing_speed_flow(
750750
marker = kwargs.get("marker", "o")
751751
marker_size = kwargs.get("marker_size", 16)
752752
axes.set_title(title)
753-
axes.scatter(flow[FLOW_COL], flow[MEAN_SPEED_COL], color=color, s=marker_size, marker=marker, **kwargs)
753+
axes.scatter(
754+
flow[FLOW_COL],
755+
flow[MEAN_SPEED_COL],
756+
color=color,
757+
s=marker_size,
758+
marker=marker,
759+
**kwargs,
760+
)
754761
axes.set_xlabel(x_label)
755762
axes.set_ylabel(y_label)
756763
return axes
@@ -1525,7 +1532,29 @@ def plot_trajectories(
15251532
traj_alpha (optional): alpha of the trajectories
15261533
traj_start_marker (optional): marker to indicate the start of the
15271534
trajectory
1535+
traj_start_color (optional): color of the start marker, defaults to
1536+
traj_color if not set
1537+
traj_start_marker_alpha (optional): alpha of the start marker,
1538+
defaults to 1.0
15281539
traj_end_marker (optional): marker to indicate the end of the trajectory
1540+
traj_end_color (optional): color of the end marker, defaults to
1541+
traj_color if not set
1542+
traj_end_marker_alpha (optional): alpha of the end marker,
1543+
defaults to 1.0
1544+
traj_start_marker_size (optional): size of the start marker, defaults
1545+
to None if not set (markers will be sized automatically by matplotlib)
1546+
traj_end_marker_size (optional): size of the end marker, defaults to
1547+
None if not set
1548+
traj_frame (optional): frame number or list of frame numbers at which
1549+
to plot a position marker for each pedestrian
1550+
traj_frame_marker (optional): marker style for the frame position
1551+
markers
1552+
traj_frame_color (optional): color of the frame position markers,
1553+
defaults to traj_color if not set
1554+
traj_frame_marker_size (optional): size of the frame position markers,
1555+
defaults to None if not set (markers will be sized automatically by matplotlib)
1556+
traj_frame_marker_alpha (optional): alpha of the frame position
1557+
markers, defaults to 1.0
15291558
border_line_color (optional): color of the borders
15301559
border_line_width (optional): line width of the borders
15311560
hole_color (optional): background color of holes
@@ -1534,7 +1563,6 @@ def plot_trajectories(
15341563
x_label (optional): label on the x-axis
15351564
y_label (optional): label on the y-axis
15361565
1537-
15381566
Returns:
15391567
matplotlib.axes.Axes instance where the trajectories are plotted
15401568
"""
@@ -1543,7 +1571,19 @@ def plot_trajectories(
15431571
traj_alpha = kwargs.pop("traj_alpha", 1.0)
15441572

15451573
traj_start_marker = kwargs.pop("traj_start_marker", "")
1574+
traj_start_color = kwargs.pop("traj_start_color", traj_color)
1575+
traj_start_marker_alpha = kwargs.pop("traj_start_marker_alpha", 1.0)
15461576
traj_end_marker = kwargs.pop("traj_end_marker", "")
1577+
traj_end_color = kwargs.pop("traj_end_color", traj_color)
1578+
traj_end_marker_alpha = kwargs.pop("traj_end_marker_alpha", 1.0)
1579+
traj_start_marker_size = kwargs.pop("traj_start_marker_size", None)
1580+
traj_end_marker_size = kwargs.pop("traj_end_marker_size", None)
1581+
traj_frame_raw = kwargs.pop("traj_frame", None)
1582+
traj_frames: Optional[List[int]] = [traj_frame_raw] if isinstance(traj_frame_raw, int) else traj_frame_raw
1583+
traj_frame_marker = kwargs.pop("traj_frame_marker", "o")
1584+
traj_frame_color = kwargs.pop("traj_frame_color", traj_color)
1585+
traj_frame_marker_size = kwargs.pop("traj_frame_marker_size", None)
1586+
traj_frame_marker_alpha = kwargs.pop("traj_frame_marker_alpha", 1.0)
15471587

15481588
title = kwargs.pop("title", "")
15491589
x_label = kwargs.pop("x_label", r"x / m")
@@ -1562,19 +1602,38 @@ def plot_trajectories(
15621602
alpha=traj_alpha,
15631603
color=traj_color,
15641604
linewidth=traj_width,
1605+
zorder=2,
15651606
)
15661607
axes.scatter(
1567-
ped[ped.frame == ped.frame.min()][X_COL],
1568-
ped[ped.frame == ped.frame.min()][Y_COL],
1569-
color=traj_color,
1608+
ped[ped[FRAME_COL] == ped[FRAME_COL].min()][X_COL],
1609+
ped[ped[FRAME_COL] == ped[FRAME_COL].min()][Y_COL],
1610+
color=traj_start_color,
15701611
marker=traj_start_marker,
1612+
s=traj_start_marker_size,
1613+
alpha=traj_start_marker_alpha,
1614+
zorder=3,
15711615
)
15721616
axes.scatter(
1573-
ped[ped.frame == ped.frame.max()][X_COL],
1574-
ped[ped.frame == ped.frame.max()][Y_COL],
1575-
color=traj_color,
1617+
ped[ped[FRAME_COL] == ped[FRAME_COL].max()][X_COL],
1618+
ped[ped[FRAME_COL] == ped[FRAME_COL].max()][Y_COL],
1619+
color=traj_end_color,
15761620
marker=traj_end_marker,
1621+
s=traj_end_marker_size,
1622+
alpha=traj_end_marker_alpha,
1623+
zorder=3,
15771624
)
1625+
if traj_frames is not None:
1626+
frame_data = ped[ped[FRAME_COL].isin(traj_frames)]
1627+
if not frame_data.empty:
1628+
axes.scatter(
1629+
frame_data[X_COL],
1630+
frame_data[Y_COL],
1631+
color=traj_frame_color,
1632+
marker=traj_frame_marker,
1633+
s=traj_frame_marker_size,
1634+
alpha=traj_frame_marker_alpha,
1635+
zorder=3,
1636+
)
15781637

15791638
axes.set_title(title)
15801639
axes.set_xlabel(x_label)
@@ -1618,8 +1677,24 @@ def plot_measurement_setup(
16181677
traj_alpha (optional): alpha of the trajectories
16191678
traj_start_marker (optional): marker to indicate the start of the
16201679
trajectory
1680+
traj_start_color (optional): color of the start marker, defaults to
1681+
traj_color if not set
1682+
traj_start_marker_size (optional): size of the start marker
1683+
traj_start_marker_alpha (optional): alpha of the start marker
16211684
traj_end_marker (optional): marker to indicate the end of the
16221685
trajectory
1686+
traj_end_color (optional): color of the end marker, defaults to
1687+
traj_color if not set
1688+
traj_end_marker_size (optional): size of the end marker
1689+
traj_end_marker_alpha (optional): alpha of the end marker
1690+
traj_frame (optional): frame number or list of frame numbers at which
1691+
to plot a position marker for each pedestrian
1692+
traj_frame_marker (optional): marker style for the frame position
1693+
markers
1694+
traj_frame_color (optional): color of the frame position markers,
1695+
defaults to traj_color if not set
1696+
traj_frame_marker_size (optional): size of the frame position markers
1697+
traj_frame_marker_alpha (optional): alpha of the frame position markers
16231698
border_line_color (optional): color of the lines of the borders
16241699
border_line_width (optional): line width of the lines of the borders
16251700
hole_color (optional): background color of holes/geometries

0 commit comments

Comments
 (0)