Visualization
Generated by docs/scripts/make_api_pages.py.
Site maps: lateral density along the road and the auxiliary-lane occupancy.
lateral_density
lateral_density(points: DataFrame, x: str = C.POS_LON, y: str = C.POS_LAT, bins: int | tuple[int, int] = (300, 120), ax: Axes | None = None, zones: Iterable[Mapping[str, float]] | None = None) -> tuple[Figure, Axes]
Plot the 2-D density of the lateral position along the road (log colour scale), auxiliary-lane zones shaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
Trajectory points with the columns |
required |
x
|
str
|
Longitudinal position column [m]. |
POS_LON
|
y
|
str
|
Lateral position column [m]. |
POS_LAT
|
bins
|
int | tuple[int, int]
|
Histogram bins (longitudinal, lateral). |
(300, 120)
|
ax
|
Axes | None
|
Axes to draw into; a new figure when None. |
None
|
zones
|
Iterable[Mapping[str, float]] | None
|
Auxiliary-lane zones with |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
occupancy_profile
occupancy_profile(points: DataFrame, edge: float | ArrayLike, x: str = C.POS_LON, y: str = C.POS_LAT, bin_m: float = 20.0, ax: Axes | None = None) -> tuple[Figure, Axes]
Plot the share [%] of the points right of a lateral edge per bin along the road.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
DataFrame
|
Trajectory points with the columns |
required |
edge
|
float | ArrayLike
|
Lateral edge [m]; a point is beyond it when its |
required |
x
|
str
|
Longitudinal position column [m]. |
POS_LON
|
y
|
str
|
Lateral position column [m]. |
POS_LAT
|
bin_m
|
float
|
Bin length along the road [m]. |
20.0
|
ax
|
Axes | None
|
Axes to draw into; a new figure when None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|
Figure style of trajlab: the palette, sizes and settings for Matplotlib and Plotly, and a hook for an external style.
One source for the figures of the documentation and the paper applications. The rules: one message per figure, sans-serif text of 7 pt at print size, figures drawn at their print width, nothing told by colour alone (Rougier, Droettboom & Bourne 2014, Ten simple rules for better figures, PLoS Comput Biol 10(9), e1003833). Data series use the colour-blind safe palette of Okabe and Ito (Wong 2011, Points of view: Color blindness, Nature Methods 8, 441); text, context and the one accent of a figure use a navy and teal palette. 7 pt text at final size follows the artwork sizing of Elsevier.
Usage::
import matplotlib.pyplot as plt
from trajlab.visualization import style
with plt.rc_context(style.matplotlib_rc()):
fig, ax = plt.subplots(figsize=style.figure_size_in(0.5))
ax.plot(t, v, color=style.CAR, ls=style.LINESTYLE["car"])
fig.savefig("figure.png", dpi=300)
figure_size_in
figure_size_in(width_fraction: float = 1.0, aspect: float = 0.625) -> tuple[float, float]
Return the size [in] of a figure drawn at its print width.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width_fraction
|
float
|
Share of the full print width |
1.0
|
aspect
|
float
|
Height divided by width [-]. |
0.625
|
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
matplotlib_rc
matplotlib_rc() -> dict[str, Any]
Return the Matplotlib settings of the style, for plt.rc_context or plt.rcParams.update.
Returns:
| Name | Type | Description |
|---|---|---|
rcParams |
dict[str, Any]
|
sans-serif 7 pt text in |
dict[str, Any]
|
background, fonts embedded as TrueType in PDF. |
plotly_layout
plotly_layout(width_pt: float = TEXTWIDTH_PT, height_pt: float = 190.0) -> dict[str, Any]
Return the Plotly layout of the style, for a layout set in points (one layout unit = 1 pt).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width_pt
|
float
|
Print width [pt]. |
TEXTWIDTH_PT
|
height_pt
|
float
|
Print height [pt]. |
190.0
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Keywords of |
plotly_axis
plotly_axis() -> dict[str, Any]
Return the Plotly axis settings of the style, for fig.update_xaxes and fig.update_yaxes.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Axis keywords: open axes, outside ticks, light grid, 7 pt text. |
use_style
use_style(apply: Callable[[Figure, Axes], object] | None = None) -> None
Register a callable run on every new figure (e.g. an external publication style).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
apply
|
Callable[[Figure, Axes], object] | None
|
Called as |
None
|
new_axes
new_axes(ax: Axes | None = None, figsize: tuple[float, float] = (6, 4)) -> tuple[Figure, Axes]
Return the given axes and its figure, or a new figure with a light grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes | None
|
Axes to draw into; a new figure is created when None. |
None
|
figsize
|
tuple[float, float]
|
Size of a new figure [in]. |
(6, 4)
|
Returns:
| Type | Description |
|---|---|
tuple[Figure, Axes]
|
|