Skip to content

plot_all

cellseg_gsontools.plotting.plot_gdf(gdf, col, ax=None, cmap=None, bin_legends=None, show_legend=True, loc='upper right', figsize=(10, 10), **kwargs)

Plot one gdf wrapper.

Parameters:

Name Type Description Default
gdf GeoDataFrame

The gdf to plot.

required
col str

The column to highlight.

required
ax Axes

The axes to plot on, by default None.

None
cmap str

The colormap to use, by default None.

None
bin_legends List[str]

The bins to use, by default None.

None
show_legend bool

Whether to show the legend, by default True.

True
loc str

The location of the legend, by default "upper right".

'upper right'
figsize tuple

The size of the figure, by default (10, 10).

(10, 10)
**kwargs Dict[str, Any]

Extra keyword arguments passed to the plot method of the GeoDataFrame.

{}

Returns:

Type Description
Axes

plt.Axes: The axes used for plotting.

Source code in cellseg_gsontools/plotting/plot.py
def plot_gdf(
    gdf: gpd.GeoDataFrame,
    col: str,
    ax: plt.Axes = None,
    cmap: str = None,
    bin_legends: List[str] = None,
    show_legend: bool = True,
    loc: str = "upper right",
    figsize: tuple = (10, 10),
    **kwargs,
) -> plt.Axes:
    """Plot one gdf wrapper.

    Parameters:
        gdf (gpd.GeoDataFrame):
            The gdf to plot.
        col (str):
            The column to highlight.
        ax (plt.Axes):
            The axes to plot on, by default None.
        cmap (str):
            The colormap to use, by default None.
        bin_legends (List[str]):
            The bins to use, by default None.
        show_legend (bool):
            Whether to show the legend, by default True.
        loc (str):
            The location of the legend, by default "upper right".
        figsize (tuple):
            The size of the figure, by default (10, 10).
        **kwargs (Dict[str, Any])):
            Extra keyword arguments passed to the `plot` method of the GeoDataFrame.

    Returns:
        plt.Axes:
            The axes used for plotting.
    """
    ax = gdf.plot(
        ax=ax,
        column=col,
        cmap=cmap,
        categorical=True,
        legend=show_legend,
        legend_kwds={"loc": loc},
        figsize=figsize,
        **kwargs,
    )
    if show_legend:
        leg = ax.legend_
        ax.add_artist(leg)

    if cmap is not None and show_legend and bin_legends is not None:
        mapping = dict([(i, s) for i, s in enumerate(bin_legends)])
        replace_legend_items(ax.get_legend(), mapping)

    return ax