How to use the geoplot.geoplot.Plot function in geoplot

To help you get started, we’ve selected a few geoplot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
# empty geometry, valid extent case: reuse prior extent, which is (0, 1) by default
        plot = Plot(self.gdf, **{**self.kwargs, **{'extent': (-1, -1, 1, 1)}})
        assert plot.ax.get_xlim() == plot.ax.get_ylim() == (0, 1)

        # nonempty geometry, valid extent case: use extent
        plot = Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (-1, -1, 1, 1)}})
        xmin, xmax = plot.ax.get_xlim()
        ymin, ymax = plot.ax.get_ylim()
        assert xmin == -1
        assert xmax == 1
        assert ymin == -1
        assert ymax == 1

        # nonempty geometry, numerically invalid extent case: raise
        with pytest.raises(ValueError):
            Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (-181, 0, 1, 1)}})
        with pytest.raises(ValueError):
            Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (0, -91, 1, 1)}})
        with pytest.raises(ValueError):
            Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (0, 0, 181, 1)}})
        with pytest.raises(ValueError):
            Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (0, 0, 1, 91)}})

        # nonempty geometry, zero extent case: warn and relax (cartopy behavior)
        with pytest.warns(UserWarning):
            Plot(self.nonempty_gdf, **{**self.kwargs, **{'extent': (0, 0, 0, 0)}})
github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
def test_init_ax(self):
        """Test that the passed axis is set."""
        _, ax = plt.subplots(figsize=(2, 2))
        plot = Plot(self.gdf, **{**self.kwargs, **{'ax': ax}})
        assert plot.figsize == (2, 2)

        ax = plt.axes(projection=ccrs.PlateCarree())
        plot = Plot(self.gdf, **{**self.kwargs, **{'ax': ax}})
        assert plot.ax == ax

        # non-default user-set figure sizes are ignored with a warning when ax is also set
        with pytest.warns(UserWarning):
            Plot(self.gdf, **{**self.kwargs, **{'figsize': (1, 1), 'ax': ax}})
github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
def test_init_ax(self):
        """Test that the passed axis is set."""
        _, ax = plt.subplots(figsize=(2, 2))
        plot = Plot(self.gdf, **{**self.kwargs, **{'ax': ax}})
        assert plot.figsize == (2, 2)

        ax = plt.axes(projection=ccrs.PlateCarree())
        plot = Plot(self.gdf, **{**self.kwargs, **{'ax': ax}})
        assert plot.ax == ax

        # non-default user-set figure sizes are ignored with a warning when ax is also set
        with pytest.warns(UserWarning):
            Plot(self.gdf, **{**self.kwargs, **{'figsize': (1, 1), 'ax': ax}})
github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
def test_no_geometry_col(self):
        """Test the requirement that the geometry column is set."""
        with pytest.raises(ValueError):
            Plot(gpd.GeoDataFrame(), **self.kwargs)
github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
)
        xmin, xmax = plot.ax.get_xlim()
        ymin, ymax = plot.ax.get_ylim()
        assert xmin < -1
        assert xmax > 1
        assert ymin < -1
        assert ymax > 1

        # empty geometry, valid extent case: reuse prior extent, which is (0, 1) by default
        plot = Plot(self.gdf, **{
            **self.kwargs, **{'extent': (-1, -1, 1, 1), 'projection': gcrs.PlateCarree()}
        })
        assert plot.ax.get_xlim() == plot.ax.get_ylim() == (0, 1)

        # nonempty geometry, valid extent case: use extent
        plot = Plot(self.nonempty_gdf, **{
            **self.kwargs, **{'extent': (-1, -1, 1, 1), 'projection': gcrs.PlateCarree()}
        })
        xmin, xmax = plot.ax.get_xlim()
        ymin, ymax = plot.ax.get_ylim()
        assert xmin == -1
        assert xmax == 1
        assert ymin == -1
        assert ymax == 1

        # nonempty geometry, unsatisfiable extent case: warn and fall back to default
        with pytest.warns(UserWarning):
            # Orthographic can only show one half of the world at a time
            Plot(self.nonempty_gdf, **{
                **self.kwargs,
                **{'extent': (-180, -90, 180, 90), 'projection': gcrs.Orthographic()}
            })
github ResidentMario / geoplot / geoplot / geoplot.py View on Github external
`_.
    figsize : (x, y) tuple, optional
        Sets the size of the plot figure (in inches).
    ax : AxesSubplot or GeoAxesSubplot instance, optional
        If set, the ``matplotlib.axes.AxesSubplot`` or ``cartopy.mpl.geoaxes.GeoAxesSubplot``
        instance to paint the plot on. Defaults to a new axis.
    kwargs: dict, optional
        Keyword arguments to be passed to the underlying matplotlib `Polygon patches
        `_.

    Returns
    -------
    ``AxesSubplot`` or ``GeoAxesSubplot``
        The plot axis.
    """
    class WebmapPlot(Plot):
        # webmap is restricted to the WebMercator projection, which requires special axis and
        # projection initialization rules to get right.
        def __init__(self, df, **kwargs):
            if isinstance(ax, GeoAxesSubplot):
                proj_name = ax.projection.__class__.__name__
                if proj_name != 'WebMercator':
                    raise ValueError(
                        f'"webmap" is only compatible with the "WebMercator" projection, but '
                        f'the input axis is in the {proj_name!r} projection instead. To fix, '
                        f'pass "projection=gcrs.WebMercator()" to the axis initializer.'
                    )
                super().__init__(df, projection=projection, **kwargs)
            elif isinstance(ax, mpl.axes.Axes):
                raise ValueError(
                    f'"webmap" is only compatible with the "WebMercator" projection, but '
                    f'the input axis is unprojected. To fix, pass "projection=gcrs.WebMercator()" '