Plot a group of polylines with the specified config. Args: polylines: Collection of (N, 2) polylines to plot. style: Style of the line to plot (e.g. `-` for solid, `--` for dashed) line_width: Desired width for the plotted lines. alpha: Desired alpha for the plot
(
ax,
polylines: List[np.ndarray],
cmap="spring",
linewidth=3,
arrow: bool = True,
reverse: bool = False,
alpha=0.5,
zorder=100,
color_change: bool = True,
color=None,
linestyle="-",
label=None,
)
| 138 | |
| 139 | |
| 140 | def plot_polyline( |
| 141 | ax, |
| 142 | polylines: List[np.ndarray], |
| 143 | cmap="spring", |
| 144 | linewidth=3, |
| 145 | arrow: bool = True, |
| 146 | reverse: bool = False, |
| 147 | alpha=0.5, |
| 148 | zorder=100, |
| 149 | color_change: bool = True, |
| 150 | color=None, |
| 151 | linestyle="-", |
| 152 | label=None, |
| 153 | ) -> None: |
| 154 | """Plot a group of polylines with the specified config. |
| 155 | |
| 156 | Args: |
| 157 | polylines: Collection of (N, 2) polylines to plot. |
| 158 | style: Style of the line to plot (e.g. `-` for solid, `--` for dashed) |
| 159 | line_width: Desired width for the plotted lines. |
| 160 | alpha: Desired alpha for the plotted lines. |
| 161 | color: Desired color for the plotted lines. |
| 162 | """ |
| 163 | if isinstance(color, str): |
| 164 | color = [color] * len(polylines) |
| 165 | |
| 166 | for i, polyline in enumerate(polylines): |
| 167 | inter_poly = interpolate_centerline(polyline, 50) |
| 168 | # inter_poly = polyline[...,:2] |
| 169 | |
| 170 | if arrow: |
| 171 | point = inter_poly[-1] |
| 172 | diff = inter_poly[-1] - inter_poly[-2] |
| 173 | diff = diff / np.linalg.norm(diff) |
| 174 | if color_change: |
| 175 | c = plt.cm.get_cmap(cmap)(0) |
| 176 | else: |
| 177 | c = color[i] |
| 178 | arrow = ax.quiver( |
| 179 | point[0], |
| 180 | point[1], |
| 181 | diff[0], |
| 182 | diff[1], |
| 183 | alpha=alpha, |
| 184 | scale_units="xy", |
| 185 | scale=0.25, |
| 186 | minlength=0.5, |
| 187 | zorder=zorder - 1, |
| 188 | color=c, |
| 189 | ) |
| 190 | |
| 191 | if color_change: |
| 192 | arc = get_polyline_arc_length(inter_poly) |
| 193 | polyline = inter_poly.reshape(-1, 1, 2) |
| 194 | segment = np.concatenate([polyline[:-1], polyline[1:]], axis=1) |
| 195 | norm = plt.Normalize(arc.min(), arc.max()) |
| 196 | lc = LineCollection( |
| 197 | segment, cmap=cmap, norm=norm, zorder=zorder, alpha=alpha, label=label |
no test coverage detected