Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import numpy as np
import geopandas as gpd
from shapely.geometry import Polygon
from matplotlib.colors import Normalize
import matplotlib.pyplot as plt
from geoplot import utils
from geoplot import (
pointplot, voronoi, kdeplot, polyplot, webmap, choropleth, cartogram, quadtree,
sankey
)
from geoplot.crs import AlbersEqualArea, WebMercator
np.random.seed(42)
p_srs = gpd.GeoSeries(utils.gaussian_points(n=100))
p_df = gpd.GeoDataFrame(geometry=p_srs)
p_df = p_df.assign(var=p_df.geometry.map(lambda p: abs(p.y) + abs(p.x)))
p_df = p_df.assign(var_cat=np.floor(p_df['var'] // (p_df['var'].max() / 5)).astype(str))
poly_df = gpd.GeoDataFrame(geometry=utils.gaussian_polygons(p_srs.geometry, n=10))
poly_df = poly_df.assign(
var=poly_df.geometry.centroid.x.abs() + poly_df.geometry.centroid.y.abs()
)
ls_df = gpd.GeoDataFrame(geometry=utils.gaussian_linestrings(p_srs.geometry))
ls_df = ls_df.assign(var=ls_df.geometry.centroid.x.abs() + ls_df.geometry.centroid.y.abs())
clip_geom = gpd.GeoSeries(Polygon([[-10, -10], [10, -10], [10, 10], [-10, 10]]))
non_clip_geom = gpd.GeoSeries(Polygon([[-30, -30], [30, -30], [30, 30], [-30, 30]]))
def identity_scale(minval, maxval):
)
from geoplot.crs import AlbersEqualArea, WebMercator
np.random.seed(42)
p_srs = gpd.GeoSeries(utils.gaussian_points(n=100))
p_df = gpd.GeoDataFrame(geometry=p_srs)
p_df = p_df.assign(var=p_df.geometry.map(lambda p: abs(p.y) + abs(p.x)))
p_df = p_df.assign(var_cat=np.floor(p_df['var'] // (p_df['var'].max() / 5)).astype(str))
poly_df = gpd.GeoDataFrame(geometry=utils.gaussian_polygons(p_srs.geometry, n=10))
poly_df = poly_df.assign(
var=poly_df.geometry.centroid.x.abs() + poly_df.geometry.centroid.y.abs()
)
ls_df = gpd.GeoDataFrame(geometry=utils.gaussian_linestrings(p_srs.geometry))
ls_df = ls_df.assign(var=ls_df.geometry.centroid.x.abs() + ls_df.geometry.centroid.y.abs())
clip_geom = gpd.GeoSeries(Polygon([[-10, -10], [10, -10], [10, 10], [-10, 10]]))
non_clip_geom = gpd.GeoSeries(Polygon([[-30, -30], [30, -30], [30, 30], [-30, 30]]))
def identity_scale(minval, maxval):
def scalar(val):
return 10
return scalar
def axis_initializer(f):
def wrapped(_self):
try:
f(_self)
finally:
from geoplot import utils
from geoplot import (
pointplot, voronoi, kdeplot, polyplot, webmap, choropleth, cartogram, quadtree,
sankey
)
from geoplot.crs import AlbersEqualArea, WebMercator
np.random.seed(42)
p_srs = gpd.GeoSeries(utils.gaussian_points(n=100))
p_df = gpd.GeoDataFrame(geometry=p_srs)
p_df = p_df.assign(var=p_df.geometry.map(lambda p: abs(p.y) + abs(p.x)))
p_df = p_df.assign(var_cat=np.floor(p_df['var'] // (p_df['var'].max() / 5)).astype(str))
poly_df = gpd.GeoDataFrame(geometry=utils.gaussian_polygons(p_srs.geometry, n=10))
poly_df = poly_df.assign(
var=poly_df.geometry.centroid.x.abs() + poly_df.geometry.centroid.y.abs()
)
ls_df = gpd.GeoDataFrame(geometry=utils.gaussian_linestrings(p_srs.geometry))
ls_df = ls_df.assign(var=ls_df.geometry.centroid.x.abs() + ls_df.geometry.centroid.y.abs())
clip_geom = gpd.GeoSeries(Polygon([[-10, -10], [10, -10], [10, 10], [-10, 10]]))
non_clip_geom = gpd.GeoSeries(Polygon([[-30, -30], [30, -30], [30, 30], [-30, 30]]))
def identity_scale(minval, maxval):
def scalar(val):
return 10
return scalar
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)
pytest.param(gcrs.TransverseMercator(central_longitude=45), marks=pytest.mark.xfail),
pytest.param(gcrs.TransverseMercator(central_latitude=45), marks=pytest.mark.xfail),
pytest.param(gcrs.LambertAzimuthalEqualArea(central_longitude=45), marks=pytest.mark.xfail),
gcrs.LambertAzimuthalEqualArea(central_latitude=45),
])
def test_partially_parameterized_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()
gcrs.LambertConformal(central_longitude=45, central_latitude=45),
gcrs.Orthographic(central_longitude=45, central_latitude=45),
gcrs.Stereographic(central_longitude=45, central_latitude=45),
pytest.param(
gcrs.TransverseMercator(central_longitude=45, central_latitude=45),
marks=pytest.mark.xfail
),
gcrs.LambertAzimuthalEqualArea(central_longitude=45, central_latitude=45),
])
def test_fully_parameterized_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()
gcrs.Orthographic(),
gcrs.Stereographic(),
pytest.param(gcrs.TransverseMercator(), marks=pytest.mark.xfail),
gcrs.LambertAzimuthalEqualArea(),
gcrs.WebMercator()
])
def test_basic_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()
gcrs.OSGB(),
])
def test_basic_non_global_projections(proj, countries):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
gplt.polyplot(countries, proj)
return plt.gcf()
pytest.param(gcrs.Orthographic(), marks=pytest.mark.xfail),
gcrs.Stereographic(),
pytest.param(gcrs.TransverseMercator(), marks=pytest.mark.xfail),
gcrs.LambertAzimuthalEqualArea(),
gcrs.WebMercator()
])
def test_subplots_global_projections(proj, countries):
gplt.polyplot(countries, proj, ax=plt.subplot(2, 1, 1, projection=proj)).set_global()
gplt.polyplot(countries, proj, ax=plt.subplot(2, 1, 2, projection=proj)).set_global()
return plt.gcf()
def test_fully_parameterized_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()