def display_map3(gdf, clip, proj): # Setup the Voronoi axes; this creates the Voronoi regions ax = geoplot.voronoi( gdf, # Define the GeoPandas DataFrame hue='total_crimes', # df column used to color regions clip=clip, # Define the voronoi clipping (map edge) projection=proj, # Define the Projection legend=True, # Create a legend edgecolor='white', # Color of the voronoi boundaries ) # Render the plot with a base map geoplot.choropleth( chicago, # Base Map ax=ax, # Axis attribute we created above extent=chicago. total_bounds, # Set plotting boundaries to base map boundaries edgecolor='black', # Color of base map's edges linewidth=1, # Width of base map's edge lines zorder=1 # Plot base map edges above the voronoi regions )
def display_map1(gdf, clip, proj): # Setup the Voronoi axes; this creates the Voronoi regions ax = geoplot.voronoi( gdf, # Define the GeoPandas DataFrame #hue='values', # df column used to color regions clip=clip, # Define the voronoi clipping (map edge) projection=proj, # Define the Projection #cmap = 'Reds', # color set #k = None, # No. of discretized buckets to create #legend = True, # Create a legend #edgecolor = 'white', # Color of the voronoi boundaries #linewidth = 0.01 # width of the voronoi boundary lines ) # Render the plot with a base map geoplot.polyplot( chicago, # Base Map ax=ax, # Axis attribute we created above extent=chicago. total_bounds, # Set plotting boundaries to base map boundaries edgecolor='black', # Color of base map's edges linewidth=1, # Width of base map's edge lines zorder=1 # Plot base map edges above the voronoi regions )
import quilt from quilt.data.ResidentMario import geoplot_data import geopandas as gpd boroughs = gpd.read_file(geoplot_data.nyc_boroughs()) injurious_collisions = gpd.read_file(geoplot_data.nyc_injurious_collisions()) # A plot type using Voronoi tessellation: https://en.wikipedia.org/wiki/Voronoi_diagram import geoplot as gplt import matplotlib.pyplot as plt f, axarr = plt.subplots(1, 2, figsize=(16, 8)) gplt.voronoi(injurious_collisions.head(1000), edgecolor='lightsteelblue', linewidth=0.5, ax=axarr[0]) gplt.polyplot(boroughs, linewidth=0.5, ax=axarr[0]) gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds', edgecolor='white', clip=boroughs.geometry, linewidth=0.5, categorical=True, ax=axarr[1]) gplt.polyplot(boroughs, linewidth=1, ax=axarr[1]) axarr[0].axis('off') axarr[1].axis('off') plt.suptitle("Injurious Car Crashes in New York City, 2016", fontsize=20, y=0.95) plt.savefig("nyc-collisions-voronoi.png", bbox_inches='tight', pad_inches=0)
from shapely.geometry import Point import matplotlib.pyplot as plt import matplotlib.patches as mpatches from matplotlib import cm, colors df_map = gpd.GeoDataFrame.from_file('Virtual_Map1.shp') df_city = pd.read_csv("Virtual_City.csv") geom = gpd.GeoSeries( [Point(x, y) for x, y in zip(df_city.long.values, df_city.lat.values)]) df_city = gpd.GeoDataFrame(df_city, geometry=geom) #--------------------------------- (a)黑白沃罗诺伊图.---------------------------------------- ax1 = gplt.voronoi( df_city, #projection=gcrs.AlbersEqualArea(), clip=df_map, linewidth=0.5, #hue='orange', cmap='Reds',k=5, legend=False, edgecolor='k') ax2 = gplt.pointplot(df_city, color='white', s=10, edgecolors='k', ax=ax1) #zorder=2, gplt.polyplot(df_map, edgecolor='none', facecolor='lightgray', ax=ax1) #zorder=1, #plt.savefig('沃罗诺伊地图2.pdf') #--------------------------------- (b)彩色沃罗诺伊图.---------------------------------------- ax = gplt.voronoi( df_city, #projection=gcrs.AlbersEqualArea(), clip=df_map, hue='city',
def test_clip_params_geometric(kwargs): return voronoi(p_df, **kwargs).get_figure()
scale = query, limits = (30, 30), legend = True, #legend_values = [-1,1], #legend_labels = ['negative','positive'], ax = Us_ax) plt.title(str(title)+', USA') Us_ax1 = gplt.polyplot(USA,linewidth=0.7 #,figsize = size ) gplt.voronoi(Us_gdf, hue = query, cmap = 'rainbow', clip = USA, k = None, linewidth = 0.1, alpha = 0.9, #scale = query, #limits = (30, 30), legend = True,ax = Us_ax1) plt.title(str(title)+', USA') Jp_ax =gplt.polyplot(world,linewidth=0.7) gplt.pointplot(Jp_gdf, hue = query, cmap = 'rainbow', k = 2, alpha = 0.8, scale = query, limits = (30, 30),
# three-dimensional heatmap on it using ``kdeplot``. ax = geoplot.kdeplot(collisions, clip=boroughs.geometry, shade=True, cmap='Reds', projection=geoplot.crs.AlbersEqualArea()) geoplot.polyplot(boroughs, ax=ax, zorder=1) ############################################################################### # Alternatively, we may partition the space into neighborhoods automatically, # using Voronoi tessellation. This is a good way of visually verifying whether # or not a certain data column is spatially correlated. ax = geoplot.voronoi(collisions.head(1000), projection=geoplot.crs.AlbersEqualArea(), clip=boroughs.simplify(0.001), hue='NUMBER OF PERSONS INJURED', cmap='Reds', k=None, legend=True, edgecolor='white') geoplot.polyplot(boroughs, edgecolor='black', zorder=1, ax=ax) ############################################################################### # These are just some of the plots you can make with Geoplot. There are # many other possibilities not covered in this brief introduction. For more # examples, refer to the # `Gallery <https://residentmario.github.io/geoplot/gallery/index.html>`_ in # the Geoplot documentation.
geoplot.cartogram(df[df['continent'] == 'Africa'], scale='pop_est', limits=(0.2, 1), figsize=(7, 8)) ############################################################################### # If we have data in the shape of points in space, we may generate a # three-dimensional heatmap on it using ``kdeplot``. This example also # demonstrates how easy it is to stack plots on top of one another. ax = geoplot.kdeplot(injurious_collisions.sample(1000), shade=True, shade_lowest=False, clip=boroughs.geometry) geoplot.polyplot(boroughs, ax=ax) ############################################################################### # Alternatively, we may partition the space into neighborhoods automatically, # using Voronoi tessellation. ax = geoplot.voronoi( injurious_collisions.sample(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds', scheme='fisher_jenks', clip=boroughs.geometry, linewidth=0) geoplot.polyplot(boroughs, ax=ax) ############################################################################### # Again, these are just some of the plots you can make with Geoplot. There are # several other possibilities not covered in this brief introduction. For more # examples, refer to the # `Gallery <https://residentmario.github.io/geoplot/gallery.html>`_ in the # Geoplot documentation.
############################################################################### # If we have data in the shape of points in space, we may generate a # three-dimensional heatmap on it using ``kdeplot``. This example also # demonstrates how easy it is to stack plots on top of one another. ax = geoplot.kdeplot(injurious_collisions.sample(1000), shade=True, shade_lowest=False, clip=boroughs.geometry) geoplot.polyplot(boroughs, ax=ax) ############################################################################### # Alternatively, we may partition the space into neighborhoods automatically, # using Voronoi tessellation. ax = geoplot.voronoi(injurious_collisions.sample(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds', scheme='fisher_jenks', clip=boroughs.geometry, linewidth=0) geoplot.polyplot(boroughs, ax=ax) ############################################################################### # Again, these are just some of the plots you can make with Geoplot. There are # several other possibilities not covered in this brief introduction. For more # examples, refer to the # `Gallery <https://residentmario.github.io/geoplot/gallery.html>`_ in the # Geoplot documentation.
def geospatial_viz(geo_data_url, point_data_url=None, att_var=None, map_type=None): ''' function to visualize the attribute information in map. (eg, population in states) geo_att_data: geodataframe that contains both geometry and attributes info att_var: the attributes to be visualized in the map map_type: string, the type of map to be viz. pointplot, choropleth, voronoi if point_data = None, att_var must be from geo_data ''' geo_data = gpd.read_file(geo_data_url) print(geo_data.head()) if point_data_url == 'No point attribute data': if att_var is None: ax = gplt.polyplot(geo_data, figsize=(10, 5)) ax.set_title('plain map of continental USA', fontsize=16) else: if map_type == 'choropleth': scheme = mc.FisherJenks(geo_data[att_var], k=5) labels = scheme.get_legend_classes() ax = gplt.polyplot(geo_data, projection=gcrs.AlbersEqualArea()) gplt.choropleth(geo_data, hue=att_var, edgecolor='white', linewidth=1, cmap='Blues', legend=True, scheme=scheme, legend_labels=labels, ax=ax) ax.set_title('{} in the continental US'.format(att_var), fontsize=16) if map_type == "cartogram": gplt.cartogram(geo_data, scale=att_var, edgecolor='black', projection=gcrs.AlbersEqualArea()) else: point_data = gpd.read_file(point_data_url) scheme = mc.Quantiles(point_data[att_var], k=5) labels = scheme.get_legend_classes() if map_type == 'pointplot': if isinstance(point_data.geometry[0], shapely.geometry.point.Point): ax = gplt.polyplot(geo_data, edgecolor='white', facecolor='lightgray', figsize=(12, 8) #projection = gcrs.AlbersEqualArea() ) gplt.pointplot(point_data, ax=ax, hue=att_var, cmap='Blues', scheme=scheme, scale=att_var, legend=True, legend_var='scale', legend_kwargs={"loc": 'lower right'}, legend_labels=labels) ax.set_title( 'Cities in the continental US, by population 2010', fontsize=16) else: print('Geometry data type not valid') if map_type == "voronoi": # check uniqueness of coordinates duplicates = point_data.geometry.duplicated() point_data_unique = point_data[-duplicates] proj = gplt.crs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5) ax = gplt.voronoi(point_data_unique, hue=att_var, clip=geo_data, projection=proj, cmap='Blues', legend=True, edgecolor="white", linewidth=0.01) gplt.polyplot(geo_data, ax=ax, extent=geo_data.total_bounds, edgecolor="black", linewidth=1, zorder=1) plt.title("{} in US cities".format(att_var), fontsize=16)
hue=query, cmap='plasma', k=None, alpha=0.8, scale=query, limits=(25, 25), legend=True, ax=Us_ax) #plt.title(str(title)+', USA') Us_ax1 = gplt.polyplot(USA, linewidth=0.7, figsize=(80, 60)) gplt.voronoi(Us_gdf, figsize=(80, 60), hue=query, cmap='plasma', clip=USA, k=None, linewidth=0.1, alpha=0.9, legend=True, ax=Us_ax1) #plt.title(str(title)+', USA') Jp_ax = gplt.polyplot(world, linewidth=0.7) gplt.pointplot(Jp_gdf, hue=query, cmap='plasma', k=None, alpha=0.8, scale=query, limits=(20, 20),
def test_clip_params_geometric(kwargs): # ignore warning from changed GeoSeries.isna behavior import warnings with warnings.catch_warnings(): warnings.filterwarnings('ignore', 'GeoSeries.isna', UserWarning) return voronoi(p_df, **kwargs).get_figure()
""" Voronoi of Melbourne primary schools ==================================== This example shows a ``pointplot`` combined with a ``voronoi`` mapping primary schools in Melbourne. Schools in outlying, less densely populated areas serve larger zones than those in central Melbourne. This example inspired by the `Melbourne Schools Zones Webmap <http://melbourneschoolzones.com/>`_. """ import geopandas as gpd import geoplot as gplt import geoplot.crs as gcrs import pandas as pd import matplotlib.pyplot as plt melbourne = gpd.read_file(gplt.datasets.get_path('melbourne')) melbourne_primary_schools = gpd.read_file(gplt.datasets.get_path('melbourne_schools'))\ .query('School_Type == "Primary"') ax = gplt.voronoi( melbourne_primary_schools, clip=melbourne, linewidth=0.5, edgecolor='white', projection=gcrs.Mercator() ) gplt.polyplot(melbourne, edgecolor='None', facecolor='lightgray', ax=ax) gplt.pointplot(melbourne_primary_schools, color='black', ax=ax, s=1, extent=melbourne.total_bounds) plt.title('Primary Schools in Greater Melbourne, 2018') plt.savefig("melbourne-schools.png", bbox_inches='tight', pad_inches=0)
import quilt from quilt.data.ResidentMario import geoplot_data import geopandas as gpd boroughs = gpd.read_file(geoplot_data.nyc_boroughs()) injurious_collisions = gpd.read_file(geoplot_data.nyc_injurious_collisions()) # A plot type using Voronoi tessellation: https://en.wikipedia.org/wiki/Voronoi_diagram import geoplot as gplt import matplotlib.pyplot as plt f, axarr = plt.subplots(1, 2, figsize=(16, 8)) gplt.voronoi(injurious_collisions.head(1000), edgecolor='lightsteelblue', linewidth=0.5, ax=axarr[0]) gplt.polyplot(boroughs, linewidth=0.5, ax=axarr[0]) gplt.voronoi(injurious_collisions.head(1000), hue='NUMBER OF PERSONS INJURED', cmap='Reds', edgecolor='white', clip=boroughs.geometry, linewidth=0.5, categorical=True, ax=axarr[1]) gplt.polyplot(boroughs, linewidth=1, ax=axarr[1]) axarr[0].axis('off') axarr[1].axis('off')
crs = {'init': 'epsg:4326'} gdf = geopandas.GeoDataFrame(soldf, crs=crs, geometry=geometry) world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres')) USA = world.query('name == "United States"') contiguous_usa = geopandas.read_file( geoplot.datasets.get_path('contiguous_usa')) proj = gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5) with PdfPages('mapPlot.pdf') as pdf: for t in time_ranges: ax = geoplot.voronoi(gdf, projection=proj, clip=USA.simplify(0.01), hue=t, figsize=(10, 10), cmap='Reds', k=None, legend=True, edgecolor='white', linewidth=0.01) #plt.title('Predicted Future Similarity') plt.title(t) geoplot.polyplot(USA, edgecolor='black', zorder=1, ax=ax, linewidth=1, extent=contiguous_usa.total_bounds) plt.savefig(pdf, format='pdf')