コード例 #1
0
    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}})
コード例 #2
0
    def test_base_init(self):
        """Test the base init all plotters pass to Plot."""
        plot = Plot(self.gdf, **self.kwargs)
        assert plot.figsize == (8, 6)
        assert isinstance(plot.ax, SubplotBase)  # SO 11690597
        assert plot.extent == None
        assert plot.projection == None

        plot = Plot(self.gdf, **{**self.kwargs, **{'projection': gcrs.PlateCarree()}})
        assert plot.figsize == (8, 6)
        assert isinstance(plot.ax, GeoAxesSubplot)
        assert plot.extent == None
        assert isinstance(plot.projection, ccrs.PlateCarree)
コード例 #3
0
    def test_init_extent_geoaxes(self):
        """Test the extent setter code in the GeoAxes case."""
        # default, empty geometry case: set extent to default value of (0, 1)
        plot = Plot(self.gdf, **{**self.kwargs, **{'projection': gcrs.PlateCarree()}})
        assert plot.ax.get_xlim() == plot.ax.get_ylim() == (0, 1)

        # default, non-empty geometry case: use a (relaxed) geometry envelope
        plot = Plot(
            gpd.GeoDataFrame(geometry=[Point(-1, -1), Point(1, 1)]), 
            **{**self.kwargs, **{'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

        # 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()}
            })
コード例 #4
0
    def test_init_extent_axes(self):
        """Test the extent setter code in the Axes case."""
        # default, empty geometry case: set extent to default value of (0, 1)
        plot = Plot(self.gdf, **self.kwargs)
        assert plot.ax.get_xlim() == plot.ax.get_ylim() == (0, 1)

        # default, non-empty geometry case: use a (relaxed) geometry envelope
        plot = Plot(gpd.GeoDataFrame(geometry=[Point(-1, -1), Point(1, 1)]), **self.kwargs)
        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)}})
        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)}})
コード例 #5
0
 def test_init_projection(self):
     """Test that passing a projection works as expected."""
     plot = Plot(self.gdf, **{
         **self.kwargs, 'projection': gcrs.PlateCarree()
     })
     assert isinstance(plot.projection, ccrs.PlateCarree)
コード例 #6
0
 def test_no_geometry_col(self):
     """Test the requirement that the geometry column is set."""
     with pytest.raises(ValueError):
         Plot(gpd.GeoDataFrame(), **self.kwargs)