import geoplot.crs as gcrs import geopandas as gpd import matplotlib.pyplot as plt import warnings @pytest.fixture(scope="module") def countries(): return gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')) @pytest.mark.mpl_image_compare @pytest.mark.parametrize("proj", [ 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),
""" 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)
def plotme(week=weeks[-1][0], startweek=weeks[-1][0], webmap=False, setnorm=False, stddev=1, savename='RecentMap.jpg', closefig=False, figsize=(25, 14)): projectioncode = 'EPSG:3395' fig = plt.figure(figsize=figsize) spec = gridspec.GridSpec(ncols=2, nrows=1, width_ratios=[1, 10]) colname = week.strftime('%Y-%m-%d') + '_chg' validmask = np.logical_not( np.logical_or(np.isnan(df[colname]), np.isinf(df[colname]))) normmin, normmax = (df[validmask][colname].min(), df[validmask][colname].max()) print("DataMin=%d\tDataMax=%d" % (normmin, normmax)) if webmap: ax1 = fig.add_subplot(spec[1], projection=gcrs.WebMercator()) gplt.webmap(df, ax=ax1) projectioncode = 'EPSG:3785' else: ax1 = fig.add_subplot(spec[1], projection=gcrs.Mercator()) if setnorm: norm = Normalize(vmin=setnorm[0], vmax=setnorm[1], clip=True) else: #maxmin = np.max(np.abs([df[colname].min(),df[colname].max()])) #norm = Normalize(vmin=-maxmin,vmax=maxmin) norm = Normalize(vmin=normmin, vmax=normmax.max()) gplt.choropleth(df[validmask], zorder=10, hue=colname, norm=norm, legend=True, ax=ax1, extent=extent, edgecolor='black', cmap='RdYlGn_r') #color NaNs and inf gplt.polyplot(df[np.logical_not(validmask)], facecolor='#0000FF', zorder=20, ax=ax1, extent=extent) fig.suptitle( "Covid-19 Week to Week %% Change in New Cases by Parish for %s" % week.strftime('%b %d, %Y').ljust(14)) ax2 = fig.add_subplot(spec[0]) ax2.set_title('Weekly New Cases for Louisiana') ax2.barh(la_series.index, la_series, color='y', height=6.5, label='Weekly New Cases') ax2.axhline(week, color='red', label='Current Week') ax2.yaxis.set_major_formatter(DateFormatter('%b %d')) for tick in ax2.get_yticklabels(): tick.set_rotation(90) ax2.legend() fig.text(0.78, 0.93, week.strftime('%b %d, %Y').rjust(12), fontsize=18, fontfamily='monospace', bbox=dict(boxstyle='round', facecolor='#ffffa8', alpha=0.7)) #get outliers mean = df[validmask][colname].mean() outdev = df[validmask][colname].std() * stddev print("outdev=%d" % outdev) label_outliers = df[np.abs(df[colname] - mean) > outdev] labels = label_outliers.append(label_places).drop_duplicates() centroids = labels['geometry'].to_crs(projectioncode).centroid for x, y, name in zip(centroids.x, centroids.y, labels['NAME']): ax1.annotate(name.replace(' ', "\n"), xy=(x, y), xytext=(0, -6), textcoords="offset points", zorder=50, ha='center', va='top') centroids = df['geometry'].to_crs(projectioncode).centroid for x, y, value in zip(centroids.x, centroids.y, df[colname]): ax1.annotate(labelgen(value), xy=(x, y), xytext=(0, 6), textcoords="offset points", zorder=50, ha='center', va='center', fontsize=15, bbox=dict(boxstyle='round', facecolor=getfacecolor(value), alpha=0.4)) fig.tight_layout() if savename != None: fig.savefig(savename) if closefig: plt.close() return norm
layerMissing = allZipNA.to_crs("EPSG:3395").plot(edgecolor='grey', color='grey', ax=layerBorder) WApoints.to_crs("EPSG:3395").plot(color='black', markersize=0.1, alpha=0.1, ax=layerBorder) #%% import geoplot.crs as gcrs #activating! layerBorder = gplt.polyplot( waBorder, projection=gcrs.Mercator(), #HERE! edgecolor='grey', facecolor='white') layerMissing = gplt.polyplot(allZipNA, edgecolor='grey', facecolor='grey', ax=layerBorder) layerPoint = gplt.pointplot(WApoints, color='black', s=0.1, alpha=0.1, ax=layerBorder) # on top of! #%%