Example #1
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()}
            })
Example #2
0
    gcrs.PlateCarree(),
    gcrs.LambertCylindrical(),
    gcrs.Mercator(),
    gcrs.Miller(),
    gcrs.Mollweide(),
    gcrs.Robinson(),
    gcrs.Sinusoidal(),
    pytest.param(gcrs.InterruptedGoodeHomolosine(), marks=pytest.mark.xfail),
    pytest.param(gcrs.Geostationary(), marks=pytest.mark.xfail),
    gcrs.NorthPolarStereo(),
    gcrs.SouthPolarStereo(),
    gcrs.Gnomonic(),
    gcrs.AlbersEqualArea(),
    gcrs.AzimuthalEquidistant(),
    gcrs.LambertConformal(),
    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()


@pytest.mark.mpl_image_compare
@pytest.mark.parametrize("proj", [
    gcrs.EuroPP(),
Example #3
0
###############################################################################
# Plotting with Geoplot
# =====================
#
# We start out by replicating the basic GeoPandas world plot using Geoplot.
import geoplot

geoplot.polyplot(df, figsize=(8, 4))

###############################################################################
# Geoplot can re-project data into any of the map projections provided by
# CartoPy (see the list
# `here <http://scitools.org.uk/cartopy/docs/latest/crs/projections.html>`_).

import geoplot.crs as gcrs
ax = geoplot.polyplot(df, projection=gcrs.Orthographic(), figsize=(8, 4))
ax.set_global()
ax.outline_patch.set_visible(True)

###############################################################################
# ``polyplot`` is trivial and can only plot the geometries you pass to it. If
# you want to use color as a visual variable, specify a ``choropleth``. Here
# we sort GDP per person by country into five buckets by color.

geoplot.choropleth(df, hue='gdp_pp', cmap='Greens', figsize=(8, 4))

###############################################################################
# If you want to use size as a visual variable, you want a ``cartogram``. Here
# are population estimates for countries in Africa.

geoplot.cartogram(df[df['continent'] == 'Africa'],
import pandas as pd
import matplotlib.pyplot as plt
import cartopy


# This script demonstrates using the cartopy feature interface alongside geoplot.
# For more information visit http://scitools.org.uk/cartopy/docs/latest/matplotlib/feature_interface.html.


# Fetch the data. Note: this script doesn't actually work! For the moment.
airline_city_pairs = pd.read_csv('../../data/world_flights/flights.csv', index_col=0)


# Plot the data.
f, axarr = plt.subplots(2, 2, figsize=(12, 12), subplot_kw={
    'projection': gcrs.Orthographic(central_latitude=40.7128, central_longitude=-74.0059)
})
plt.suptitle('Popular Flights out of Los Angeles, 2016', fontsize=16)
plt.subplots_adjust(top=0.95)

ax = gplt.sankey(airline_city_pairs.query('Origin == "Los Angeles, CA"'), start='Starting Point', end='Ending Point',
                 projection=gcrs.Orthographic(), scale='PASSENGERS', hue='PASSENGERS', cmap='Purples', ax=axarr[0][0])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.coastlines()

ax = gplt.sankey(airline_city_pairs.query('Origin == "Los Angeles, CA"'), start='Starting Point', end='Ending Point',
                 projection=gcrs.Orthographic(), scale='PASSENGERS', hue='PASSENGERS', cmap='Purples', ax=axarr[0][1])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.stock_img()
Example #5
0
        gcrs.PlateCarree(),
        # gcrs.LambertCylindrical(),
        gcrs.Mercator(),
        gcrs.Miller(),
        gcrs.Mollweide(),
        gcrs.Robinson(),
        gcrs.Sinusoidal(),
        gcrs.InterruptedGoodeHomolosine(),
        gcrs.Geostationary(),
        gcrs.NorthPolarStereo(),
        gcrs.SouthPolarStereo(),
        gcrs.Gnomonic(),
        gcrs.AlbersEqualArea(),
        gcrs.AzimuthalEquidistant(),
        gcrs.LambertConformal(),
        gcrs.Orthographic(),
        gcrs.Stereographic(),
        gcrs.TransverseMercator(),
        gcrs.LambertAzimuthalEqualArea()
        # # TODO: Include other new ones.
    ])
def test_basic_global_projections(proj, countries):
    gplt.polyplot(countries, proj)
    ax = plt.gca()
    ax.set_global()

    return plt.gcf()


@pytest.mark.mpl_image_compare
@pytest.mark.parametrize("proj", [
Example #6
0
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
import cartopy

# load the data
la_flights = gpd.read_file(gplt.datasets.get_path('la_flights'))
la_flights = la_flights.assign(start=la_flights.geometry.map(lambda mp: mp[0]),
                               end=la_flights.geometry.map(lambda mp: mp[1]))

f, axarr = plt.subplots(2,
                        2,
                        figsize=(12, 12),
                        subplot_kw={
                            'projection':
                            gcrs.Orthographic(central_latitude=40.7128,
                                              central_longitude=-74.0059)
                        })
plt.suptitle('Popular Flights out of Los Angeles, 2016', fontsize=16)
plt.subplots_adjust(top=0.95)

ax = gplt.sankey(la_flights,
                 start='start',
                 end='end',
                 projection=gcrs.Orthographic(),
                 scale='Passengers',
                 hue='Passengers',
                 cmap='Purples',
                 ax=axarr[0][0])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.coastlines()
"""

import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
import cartopy

la_flights = gpd.read_file(gplt.datasets.get_path('la_flights'))

f, axarr = plt.subplots(2,
                        2,
                        figsize=(12, 12),
                        subplot_kw={
                            'projection':
                            gcrs.Orthographic(central_latitude=40.7128,
                                              central_longitude=-74.0059)
                        })
plt.suptitle('Popular Flights out of Los Angeles, 2016', fontsize=16)
plt.subplots_adjust(top=0.95)

ax = gplt.sankey(la_flights,
                 scale='Passengers',
                 hue='Passengers',
                 cmap='Purples',
                 k=5,
                 ax=axarr[0][0])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.coastlines()

ax = gplt.sankey(la_flights,