How to use the geoplot.utils.gaussian_polygons 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 / viz_tests.py View on Github external
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
github ResidentMario / geoplot / tests / kwarg_tests.py View on Github external
import geopandas as gpd
import matplotlib.pyplot as plt
from shapely.geometry import Point, LineString
import numpy as np
import geoplot.crs as gcrs


# Point-type DataFrame input.
list_gaussian_points = gplt.utils.gaussian_points(n=4)
dataframe_gaussian_points = gpd.GeoDataFrame(
    geometry=list_gaussian_points
).assign(hue_var=[1,2,3,4])


# Polygon-type DataFrame input.
list_gaussian_polys = gplt.utils.gaussian_polygons(gplt.utils.gaussian_points(n=1000), n=2).append(
    gplt.utils.gaussian_multi_polygons(gplt.utils.gaussian_points(n=1000), n=2)
)
dataframe_gaussian_polys = gpd.GeoDataFrame(geometry=list_gaussian_polys).assign(hue_var=[1,2,3,4])

# (Sankey) point input.
# Start and end variables.
list_start_points = [Point(a + 2, a - 2) for a in range(0, 4)]
list_end_points = [Point(a - 2, a + 2) for a in range(1, 5)]

# (Sankey) paths.
list_paths = [
    LineString([[a.x, a.y], [b.x, b.y]]) for a, b in zip(list_start_points, list_end_points)
]

# (Aggplot) geometry.
dataframe_gaussian_points = dataframe_gaussian_points.assign(mock_category=np.random.randint(1, 5))
github ResidentMario / geoplot / tests / property_tests.py View on Github external
import geoplot.crs as gcrs
import unittest
from hypothesis import given
import hypothesis.strategies as st
import geopandas as gpd
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import shapely
import numpy as np


# Define strategies.

# Static inputs.
gaussian_points = gplt.utils.gaussian_points(n=10)
gaussian_polys = gplt.utils.gaussian_polygons(gplt.utils.gaussian_points(n=100), n=2).append(
                 gplt.utils.gaussian_multi_polygons(gplt.utils.gaussian_points(n=100), n=2)
)

# Projections.
projections = st.sampled_from((None, gcrs.PlateCarree()))

# Hue data.
schemes = st.sampled_from((None, "equal_interval", "quantiles", "fisher_jenks"))
k = st.integers(min_value=4, max_value=9).map(lambda f: None if f == 4 else f)
datasets_numeric = st.lists(st.floats(allow_nan=False, allow_infinity=False, min_value=10**-10, max_value=10**10),
                            min_size=10, max_size=10, unique=True)
datasets_categorical = st.lists(st.text(st.characters(max_codepoint=1000, blacklist_categories=('Cc', 'Cs')),
                                                      max_size=20), min_size=10, max_size=10)
categorical = st.booleans()
use_hue = st.booleans()
github ResidentMario / geoplot / tests / input_tests.py View on Github external
import matplotlib.pyplot as plt
from shapely.geometry import Point, LineString
import numpy as np
import pandas as pd


# Point-type DataFrame input.
list_gaussian_points = gplt.utils.gaussian_points(n=4)
series_gaussian_points = gpd.GeoSeries(list_gaussian_points)
dataframe_gaussian_points = gpd.GeoDataFrame(
    geometry=series_gaussian_points
).assign(hue_var=[1,2,3,4])


# Polygon-type DataFrame input.
list_gaussian_polys = gplt.utils.gaussian_polygons(
    gplt.utils.gaussian_points(n=1000), n=2
).append(
    gplt.utils.gaussian_multi_polygons(gplt.utils.gaussian_points(n=1000), n=2)
)
series_gaussian_polys = gpd.GeoSeries(list_gaussian_polys)
dataframe_gaussian_polys = gpd.GeoDataFrame(
    geometry=series_gaussian_polys
).assign(hue_var=[1,2,3,4])

# Hue input.
list_hue_values = [1, 2, 3, 4]
series_hue_values = pd.Series(list_hue_values)
def map_hue_values(): return map(lambda i: list_hue_values[i], list(range(len(list_hue_values))))


# (Sankey) point input.
github ResidentMario / geoplot / tests / property_tests.py View on Github external
hue_vars(),
           scale_vars(),
           legend_vars(),
           data_kwargs)
    def test_sankey(self, projection, hue_vars, scale_vars, legend_vars, data_kwargs):
        kwargs = {'projection': projection}
        kwargs = {**kwargs, **hue_vars, **scale_vars, **legend_vars, **data_kwargs}

        try: gplt.sankey(network, **kwargs)
        finally: plt.close()


# Additional strategies
# Static inputs.
agg_gaussian_points = gplt.utils.gaussian_points(n=100)
agg_gaussian_polys = gplt.utils.gaussian_polygons(gplt.utils.gaussian_points(n=100), n=2)
agg_gaussian_multipolys = gplt.utils.gaussian_multi_polygons(gplt.utils.gaussian_points(n=100), n=2)
agg_data = gpd.GeoDataFrame(geometry=agg_gaussian_points)

# Data input.
# For quadtree mode.
mode = st.integers(min_value=0, max_value=2)
nmin = st.integers(min_value=10, max_value=21).map(lambda v: v if v < 21 else None)
nmax = st.integers(min_value=20, max_value=51).map(lambda v: v if v < 51 else None)
nsig = st.integers(min_value=0, max_value=10)

# For by mode.
cats = st.lists(st.integers(min_value=0, max_value=1), min_size=100, max_size=100)

# For geometry mode.
indexed_geometry = gpd.GeoSeries({0: agg_gaussian_polys[0], 1: agg_gaussian_multipolys[1]})