예제 #1
0
    def test_sankey(self):
        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), edgecolor='white')

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), color='white')

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), linewidth=1)

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), linestyle='--')
예제 #2
0
    def test_sankey(self):
        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), edgecolor='white')

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), color='white')

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), linewidth=1)

        gplt.sankey(path=list_paths, projection=gcrs.PlateCarree(), linestyle='--')
예제 #3
0
    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()
예제 #4
0
def pretty_plot(gg: GeoDataFrame, islands: GeoDataFrame, poly_viewsheds: GeoDataFrame, save_figure_to: str,
                proj=PROJECTION):
    x = gg[gg.apply(lambda x: not x.is_empty and x.area > 1e-9)]
    xa = GeoDataFrame(x.centroid, geometry=0, crs=islands.crs)
    xa.columns = ['geometry']
    xa_tmp = xa.reset_index()
    xa_tmp['idx'] = xa_tmp.apply(lambda y: (y.idx_a, y.idx_b), axis=1)
    xa_tmp['idx_other'] = xa_tmp.apply(lambda y: (y.idx_b, y.idx_a), axis=1)
    xa_tmp = xa_tmp.set_index('idx')
    paths = xa_tmp.join(xa_tmp, on='idx_other', lsuffix='_ab', rsuffix='_ba')
    paths = paths[paths.apply(lambda y: y.geometry_ab is not np.nan and y.geometry_ba is not np.nan, axis=1)]

    ax = gplt.polyplot(
        islands,
        projection=proj,
        figsize=(20, 20),
        color='darkgray'
    )
    gplt.polyplot(
        poly_viewsheds,
        projection=proj,
        ax=ax,
        linewidth=0,
        facecolor='lightgray',
        alpha=0.3
    )
    gplt.polyplot(
        x,
        projection=proj,
        ax=ax,
        linewidth=0,
        facecolor='red',
        alpha=0.3
    )
    gplt.sankey(
        paths,
        start='geometry_ab',
        end='geometry_ba',
        ax=ax,
        projection=proj,
        alpha=0.05,
        rasterized=False
    )

    plt.savefig(save_figure_to)
예제 #5
0
`the matplotlib documentation
<https://matplotlib.org/gallery/images_contours_and_fields/custom_cmap.html>`_.

`Click here <http://bl.ocks.org/ResidentMario/ac2db57d1c6652ddbc4112a3d318c746>`_ to see an 
interactive scrolly-panny version of this webmap built with ``mplleaflet``. To learn more about
``mplleaflet``, refer to `the mplleaflet GitHub repo <https://github.com/jwass/mplleaflet>`_.
"""

import geopandas as gpd
import geoplot as gplt
import matplotlib.pyplot as plt
import mplleaflet
from matplotlib.colors import LinearSegmentedColormap

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

colors = [(215 / 255, 193 / 255, 126 / 255), (37 / 255, 37 / 255, 37 / 255)]
cm = LinearSegmentedColormap.from_list('minard', colors)

gplt.sankey(napoleon_troop_movements,
            scale='survivors',
            limits=(0.5, 45),
            hue='direction',
            cmap=cm)
fig = plt.gcf()
plt.savefig("minard-napoelon-russia.png", bbox_inches='tight', pad_inches=0.1)

# Uncomment and run the following line of code to save as an interactive webmap.
# mplleaflet.save_html(fig, fileobj='minard-napoleon-russia.html')
예제 #6
0
# Shape the data.
troop_positions = pd.read_fwf("../../data/napoloen/troops.txt")
troop_positions = gpd.GeoDataFrame(data=troop_positions,
                                   geometry=troop_positions\
                                       .apply(lambda srs: Point(srs['long'], srs['lat']),
                                              axis='columns'))

subsrs = []
for a, b in zip(range(len(troop_positions) - 1), range(1, len(troop_positions))):
    srs = troop_positions.iloc[b]
    srs = srs.rename({'geometry': 'from'})
    srs['to'] = troop_positions.iloc[a].geometry
    subsrs.append(srs)
troop_movements = pd.concat(subsrs, axis=1).T
troop_movements = troop_movements[['survivors', 'direction', 'group', 'from', 'to']]
troop_movements['direction'] = troop_movements.direction.map(lambda d: 0 if d == 'A' else 1)


# Plot the data.

# We'll use a custom colormap, to match the one that Minard uses.
from matplotlib.colors import LinearSegmentedColormap
colors = [(215/255, 193/255, 126/255), (37/255, 37/255, 37/255)]
cm = LinearSegmentedColormap.from_list('minard', colors)


gplt.sankey(troop_movements, start='from', end='to',
            scale='survivors', limits=(0.5, 45),
            hue='direction', categorical=True, cmap=cm)
fig = plt.gcf()
mplleaflet.save_html(fig, fileobj='minard-napoleon-russia.html')
예제 #7
0
"""
Sankey of traffic volumes in Washington DC
==========================================

This example plots 
`annual average daily traffic volume <https://en.wikipedia.org/wiki/Annual_average_daily_traffic>`_
in Washington DC.
"""

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

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

gplt.sankey(dc_roads,
            projection=gcrs.AlbersEqualArea(),
            scale='aadt',
            limits=(0.1, 10),
            color='black')

plt.title("Streets in Washington DC by Average Daily Traffic, 2015")
plt.savefig("dc-street-network.png", bbox_inches='tight', pad_inches=0.1)
예제 #8
0
# Load the data (uses the `quilt` package).
import geopandas as gpd
from quilt.data.ResidentMario import geoplot_data

troop_movements = gpd.read_file(geoplot_data.napoleon_troop_movements())
troop_movements['from'] = troop_movements.geometry.map(lambda v: v[0])
troop_movements['to'] = troop_movements.geometry.map(lambda v: v[1])

# Plot the data. We'll use a custom colormap, to match the one that Minard uses.
import geoplot as gplt
import matplotlib.pyplot as plt
import mplleaflet

from matplotlib.colors import LinearSegmentedColormap
colors = [(215 / 255, 193 / 255, 126 / 255), (37 / 255, 37 / 255, 37 / 255)]
cm = LinearSegmentedColormap.from_list('minard', colors)

gplt.sankey(troop_movements,
            start='from',
            end='to',
            scale='survivors',
            limits=(0.5, 45),
            hue='direction',
            categorical=True,
            cmap=cm)
fig = plt.gcf()
mplleaflet.save_html(fig, fileobj='minard-napoleon-russia.html')
예제 #9
0
x = gpd.GeoDataFrame({'geometry': []})
for idx1, row1 in gdf.iterrows():
    for idx2, row2 in gdf.iterrows():
        if idx1 == idx2:
            continue
        if row1['district_id'] == 5 or row2['district_id'] == 5:
            continue
        dist = geodesic((row2['lat'], row2['lon']),
                        (row1['lat'], row1['lon'])).km
        if dist <= 40:
            line = LineString(
                ([Point(row1['lon'], row1['lat']), Point(row2['lon'], row2['lat'])]))
            x.loc[len(x)] = [line]

# plot
ax3 = gplt.sankey(x, figsize=(30, 30))
gplt.sankey(x2, ax=ax3, color=[1, 0, 0, 1])
gplt.polyplot(district_df, ax=ax3)
gplt.pointplot(rec, ax=ax3, color=[0, 1, 0])
gplt.pointplot(gdf, ax=ax3)
c = [1, 0, 0]
gplt.pointplot(gdf_hq, ax=ax3, color=c)

# label labs and hq
plt.rc('font', size=10)
for idx, row in gdf.iterrows():
    if row['district_id'] != 5:
        plt.text(s=row['id'], x=row['lon'], y=row['lat'])
for idx, row in district_df.iterrows():
    pt = row['geometry'].centroid
    lmao = pd.read_csv('../data/districts_data_v0.csv')
예제 #10
0
# 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()

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[1][0])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.gridlines()
예제 #11
0
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()

ax = gplt.sankey(la_flights,
                 start='start',
                 end='end',
                 projection=gcrs.Orthographic(),
                 scale='Passengers',
                 hue='Passengers',
                 cmap='Purples',
                 ax=axarr[0][1])
예제 #12
0
# Load the data (uses the `quilt` package).
import geopandas as gpd
from quilt.data.ResidentMario import geoplot_data

dc = gpd.read_file(geoplot_data.dc_roads())


# Plot the data.
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

ax = gplt.sankey(dc, path=dc.geometry, projection=gcrs.AlbersEqualArea(), scale='aadt',
                 limits=(0.1, 10))
plt.title("Streets in Washington DC by Average Daily Traffic, 2015")
plt.savefig("dc-street-network.png", bbox_inches='tight', pad_inches=0.1)
예제 #13
0
    def test_sankey(self):
        try:
            gplt.sankey(start=map_start_points(), end=map_end_points())
            gplt.sankey(start=map_start_points(), end=map_end_points())

            gplt.sankey(start=list_start_points, end=list_end_points)
            gplt.sankey(start=list_start_points, end=list_end_points)

            gplt.sankey(start=series_start_points, end=series_end_points)
            gplt.sankey(start=series_start_points, end=series_end_points)

            gplt.sankey(start=map_start_points(), end=map_end_points())
            gplt.sankey(start=map_start_points(), end=map_end_points())

            gplt.sankey(dataframe_gaussian_points, start='starts', end='ends')

            gplt.sankey(path=list_paths)
            gplt.sankey(path=series_paths)
            gplt.sankey(path=map_paths())

            gplt.sankey(dataframe_gaussian_points, path='paths')

        finally:
            plt.close('all')
예제 #14
0
    data_df, geometry=gpd.points_from_xy(data_df.lon, data_df.lat))

# get district hqs and data
gdf_hq = pd.read_csv('../data/districts_data_v0.csv')
gdf_hq = gpd.GeoDataFrame(
    gdf_hq, geometry=gpd.points_from_xy(gdf_hq.lon, gdf_hq.lat))

# get labs nearer than 40 km
x = gpd.GeoDataFrame({'geometry': []})
for idx1, row1 in gdf.iterrows():
    for idx2, row2 in gdf.iterrows():
        if idx1 == idx2:
            continue
        if row1['district_id'] == 5 and row2['district_id'] == 5:
            continue
        dist = geodesic((row2['lat'], row2['lon']),
                        (row1['lat'], row1['lon'])).km
        if dist <= 40:
            line = LineString(
                ([Point(row1['lon'], row1['lat']), Point(row2['lon'], row2['lat'])]))
            x.loc[len(x)] = [line]

# plot
ax = gplt.polyplot(district_df)
gplt.pointplot(gdf, ax=ax)
c = [1, 0, 0]
gplt.pointplot(gdf_hq, ax=ax, color=c)
gplt.sankey(x, ax=ax)

plt.show()
예제 #15
0
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,
                 scale='Passengers',
                 hue='Passengers',
                 cmap='Purples',
                 k=5,
                 ax=axarr[0][1])
ax.set_global()
ax.outline_patch.set_visible(True)
ax.stock_img()
예제 #16
0
import sys
sys.path.insert(0, '../')
import geoplot as gplt
import geoplot.crs as gcrs
import geopandas as gpd
import matplotlib.pyplot as plt

# The data being used here is the DC portion of the Federal Highway Administration's roadway traffic volume
# shapefiles, retrieved from http://www.fhwa.dot.gov/policyinformation/hpms/shapefiles.cfm. The AADT column of
# interest here is the FHA's traffic volume estimates.

# Load the data.
dc = gpd.read_file("../../data/us_roads/District_Sections.shp")

# Plot the data.
ax = gplt.sankey(dc,
                 path=dc.geometry,
                 projection=gcrs.AlbersEqualArea(),
                 scale='aadt',
                 limits=(0.1, 10))
plt.title("Streets in Washington DC by Average Daily Traffic, 2015")
plt.savefig("largest-cities-usa.png", bbox_inches='tight', pad_inches=0.1)
예제 #17
0
    def test_sankey(self):
        try:
            gplt.sankey(start=map_start_points(), end=map_end_points())
            gplt.sankey(start=map_start_points(), end=map_end_points())

            gplt.sankey(start=list_start_points, end=list_end_points)
            gplt.sankey(start=list_start_points, end=list_end_points)

            gplt.sankey(start=series_start_points, end=series_end_points)
            gplt.sankey(start=series_start_points, end=series_end_points)

            gplt.sankey(start=map_start_points(), end=map_end_points())
            gplt.sankey(start=map_start_points(), end=map_end_points())

            gplt.sankey(dataframe_gaussian_points, start='starts', end='ends')

            gplt.sankey(path=list_paths)
            gplt.sankey(path=series_paths)
            gplt.sankey(path=map_paths())

            gplt.sankey(dataframe_gaussian_points, path='paths')

        finally:
            plt.close('all')
예제 #18
0
)


# Plot the data.
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
import cartopy

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()

ax = gplt.sankey(la_flights, start='start', end='end',
                 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()

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