How to use the geoplot.utils 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.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:
github ResidentMario / geoplot / tests / mixin_tests.py View on Github external
# set props the mixin is responsible for
            legendmixin.kwargs = {
                'legend': True, 'legend_labels': None, 'legend_values': None,
                'legend_kwargs': None, 'legend_var': None
            }
            # set props controlled by the plot object initializer
            _, ax = plt.subplots(figsize=(8, 6))
            legendmixin.ax = ax
            legendmixin.figsize = (8, 6)
            legendmixin.extent = None
            legendmixin.projection = None

            # set data prop
            np.random.seed(42)
            legendmixin.df = gpd.GeoDataFrame(
                {'foo': np.random.random(100), 'geometry': utils.gaussian_points(n=100)}
            )

            # set props controlled by the hue initializer, if appropriate
            if 'hue' in legend_vars:
                legendmixin.colors = ['black'] * 100
                legendmixin.hue = legendmixin.df.foo
                legendmixin.cmap = ScalarMappable(cmap='Reds')
                legendmixin.k = None
                legendmixin.categorical = False
                legendmixin.categories = None
                legendmixin.color_kwarg = 'color'
                legendmixin.default_color = 'steelblue'

            # set props controlled by the scale initializer, if appropriate
            if 'scale' in legend_vars:
                legendmixin.scale = legendmixin.df.foo
github ResidentMario / geoplot / tests / kwarg_tests.py View on Github external
"""
Tests keyword argument inputs for types underlying geoplot functions.
"""

import sys; sys.path.insert(0, '../')
import geoplot as gplt
import unittest
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)]
github ResidentMario / geoplot / tests / input_tests.py View on Github external
"""
Tests that raw data inputs function correctly.
"""

import sys; sys.path.insert(0, '../')
import geoplot as gplt
import unittest
import geopandas as gpd
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])
github ResidentMario / geoplot / tests / property_tests.py View on Github external
import geoplot as gplt
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()