Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_fully_parameterized_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()
def test_subplots_global_projections(proj, countries):
gplt.polyplot(countries, proj, ax=plt.subplot(2, 1, 1, projection=proj)).set_global()
gplt.polyplot(countries, proj, ax=plt.subplot(2, 1, 2, projection=proj)).set_global()
return plt.gcf()
def test_polyplot(self):
gplt.polyplot(gaussian_polys, projection=None)
gplt.polyplot(gaussian_polys, projection=gcrs.PlateCarree())
plt.close()
def test_partially_parameterized_global_projections(proj, countries):
gplt.polyplot(countries, proj)
ax = plt.gca()
ax.set_global()
return plt.gcf()
1, 2, figsize=(16, 8), subplot_kw={'projection': proj}
)
axarr[0].axis('off')
axarr[1].axis('off')
gplt.voronoi(
nyc_injurious_collisions.head(1000),
edgecolor='lightsteelblue', linewidth=0.5, ax=axarr[0],
)
gplt.polyplot(nyc_boroughs, linewidth=0.5, ax=axarr[0])
gplt.voronoi(
nyc_injurious_collisions.head(1000),
hue='NUMBER OF PERSONS INJURED', cmap='Reds',
edgecolor='white', clip=nyc_boroughs.geometry,
linewidth=0.5, ax=axarr[1]
)
gplt.polyplot(nyc_boroughs, linewidth=1, ax=axarr[1])
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)
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt
trees = gpd.read_file(gplt.datasets.get_path('san_francisco_street_trees_sample'))
sf = gpd.read_file(gplt.datasets.get_path('san_francisco'))
ax = gplt.quadtree(
trees.assign(nullity=trees['Species'].notnull().astype(int)),
projection=gcrs.AlbersEqualArea(),
hue='nullity', nmax=1, cmap='Greens', k=5, legend=True,
clip=sf, edgecolor='white', linewidth=1
)
gplt.polyplot(sf, facecolor='None', edgecolor='gray', linewidth=1, zorder=2, ax=ax)
plt.savefig("san-francisco-street-trees.png", bbox_inches='tight', pad_inches=0)
)
gplt.polyplot(nyc_boroughs, ax=ax1)
ax1.set_title("Fatal Crashes in New York City, 2016")
gplt.pointplot(
nyc_injurious_collisions, projection=proj,
hue='BOROUGH', cmap='Set1',
edgecolor='white', linewidth=0.5,
scale='NUMBER OF PERSONS INJURED', limits=(4, 20),
legend=True, legend_var='scale',
legend_kwargs={'loc': 'upper left', 'markeredgecolor': 'black'},
legend_values=[20, 15, 10, 5, 1],
legend_labels=['20 Injuries', '15 Injuries', '10 Injuries', '5 Injuries', '1 Injury'],
ax=ax2
)
gplt.polyplot(nyc_boroughs, ax=ax2, projection=proj)
ax2.set_title("Injurious Crashes in New York City, 2016")
plt.savefig("nyc-collisions-map.png", bbox_inches='tight', pad_inches=0)
proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
fig = plt.figure(figsize=(10,5))
ax1 = plt.subplot(121, projection=proj)
ax2 = plt.subplot(122, projection=proj)
gplt.kdeplot(
nyc_collision_factors[
nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Failure to Yield Right-of-Way"
],
cmap='Reds',
projection=proj,
shade=True, shade_lowest=False,
clip=nyc_boroughs.geometry,
ax=ax1
)
gplt.polyplot(nyc_boroughs, zorder=1, ax=ax1)
ax1.set_title("Failure to Yield Right-of-Way Crashes, 2016")
gplt.kdeplot(
nyc_collision_factors[
nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Lost Consciousness"
],
cmap = 'Reds',
projection=proj,
shade=True, shade_lowest=False,
clip=nyc_boroughs.geometry,
ax=ax2
)
gplt.polyplot(nyc_boroughs, zorder=1, ax=ax2)
ax2.set_title("Loss of Consciousness Crashes, 2016")
plt.savefig("nyc-collision-factors.png", bbox_inches='tight', pad_inches=0.1)
proj = gcrs.AlbersEqualArea(central_latitude=40.7128, central_longitude=-74.0059)
fig = plt.figure(figsize=(10,5))
ax1 = plt.subplot(121, projection=proj)
ax2 = plt.subplot(122, projection=proj)
gplt.kdeplot(
nyc_collision_factors[
nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Failure to Yield Right-of-Way"
],
cmap='Reds',
projection=proj,
shade=True, shade_lowest=False,
clip=nyc_boroughs.geometry,
ax=ax1
)
gplt.polyplot(nyc_boroughs, zorder=1, ax=ax1)
plt.title("Failure to Yield Right-of-Way Crashes, 2016")
gplt.kdeplot(
nyc_collision_factors[
nyc_collision_factors['CONTRIBUTING FACTOR VEHICLE 1'] == "Lost Consciousness"
],
cmap = 'Reds',
projection=proj,
shade=True, shade_lowest=False,
clip=nyc_boroughs.geometry,
ax=ax2
)
gplt.polyplot(nyc_boroughs, zorder=1, ax=ax2)
plt.title("Loss of Consciousness Crashes, 2016")
plt.savefig("nyc-collision-factors.png", bbox_inches='tight', pad_inches=0.1)
def plot_state_to_ax(state, ax):
gplt.choropleth(
tickets.set_index('id').loc[:, [state, 'geometry']],
hue=state, cmap='Blues',
linewidth=0.0, ax=ax
)
gplt.polyplot(
nyc_boroughs, edgecolor='black', linewidth=0.5, ax=ax
)