Plot a (Multi)LineString/LinearRing. Note: this function is experimental, and mainly targeting (interactive) exploration, debugging and illustration purposes. Parameters ---------- line : shapely.LineString or shapely.LinearRing The line to plot. ax : matplotlib Axe
(line, ax=None, add_points=True, color=None, linewidth=2, **kwargs)
| 133 | |
| 134 | |
| 135 | def plot_line(line, ax=None, add_points=True, color=None, linewidth=2, **kwargs): |
| 136 | """Plot a (Multi)LineString/LinearRing. |
| 137 | |
| 138 | Note: this function is experimental, and mainly targeting (interactive) |
| 139 | exploration, debugging and illustration purposes. |
| 140 | |
| 141 | Parameters |
| 142 | ---------- |
| 143 | line : shapely.LineString or shapely.LinearRing |
| 144 | The line to plot. |
| 145 | ax : matplotlib Axes, default None |
| 146 | The axes on which to draw the plot. If not specified, will get the |
| 147 | current active axes or create a new figure. |
| 148 | add_points : bool, default True |
| 149 | If True, also plot the coordinates (vertices) as points. |
| 150 | color : matplotlib color specification |
| 151 | Color for the line (edgecolor under the hood) and points. |
| 152 | linewidth : float, default 2 |
| 153 | The line width for the polygon boundary. |
| 154 | **kwargs |
| 155 | Additional keyword arguments passed to the matplotlib Patch. |
| 156 | |
| 157 | Returns |
| 158 | ------- |
| 159 | Matplotlib artist (PathPatch) |
| 160 | |
| 161 | """ |
| 162 | from matplotlib.patches import PathPatch |
| 163 | from matplotlib.path import Path |
| 164 | |
| 165 | if ax is None: |
| 166 | ax = _default_ax() |
| 167 | |
| 168 | if color is None: |
| 169 | color = "C0" |
| 170 | |
| 171 | if isinstance(line, shapely.MultiLineString): |
| 172 | path = Path.make_compound_path( |
| 173 | *[Path(np.asarray(mline.coords)[:, :2]) for mline in line.geoms] |
| 174 | ) |
| 175 | else: |
| 176 | path = Path(np.asarray(line.coords)[:, :2]) |
| 177 | |
| 178 | patch = PathPatch( |
| 179 | path, facecolor="none", edgecolor=color, linewidth=linewidth, **kwargs |
| 180 | ) |
| 181 | ax.add_patch(patch) |
| 182 | ax.autoscale_view() |
| 183 | |
| 184 | if add_points: |
| 185 | line = plot_points(line, ax=ax, color=color) |
| 186 | return patch, line |
| 187 | |
| 188 | return patch |
| 189 | |
| 190 | |
| 191 | def plot_points(geom, ax=None, color=None, marker="o", **kwargs): |
searching dependent graphs…