我有纽约州立医院的地理参考数据,并想创建一个带底图的等值线图。我还尝试使用 .plot() 进行分层,但没有成功。当我为分层图运行代码时,没有显示图像,当我在上下文中运行时,我收到以下错误消息:
HTTPError:平铺 URL 导致 404 错误。仔细检查您的瓷砖网址: https ://stamen-tiles-aassl.fastly.net/terrain/24/8388574/8388589.png
康达环境:
*conda config --add channels conda-forge*
*conda config --add channels anaconda*
*conda create -n geo python=3.7.0 geopandas=0.4.0 spyder contextily*
*conda activate geo*
这就是我正在运行的,从头到尾:
import pandas as pd
import geopandas as gp
import contextily as ctx
import matplotlib.pyplot as plt
from shapely.geometry import Point
%matplotlib inline
usa = gp.read_file("https://alicia.data.socrata.com/resource/cap4-bs3u.geojson")
NY_state = usa.loc[usa['state_abbr'] == 'NY']
ax = NY_state.to_crs(epsg=3857).plot(figsize=(10,10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ax)
ax
上述步骤运行良好,并创建了一张漂亮的地图。以下是我如何操纵纽约州立医院数据以创建 GeoDataFrame 和等值线图的值(观察到的感染/预测的感染)
polpro_new = pd.read_csv('https://health.data.ny.gov/api/views/utrt-
zdsi/rows.csv?accessType=DOWNLOAD&api_foundry=true' )
polpro_new.rename(columns = {'New Georeferenced Column':'Georef'}, inplace = True)
Geo_df = polpro_new.Georef.str.split(expand=True)
Geo_df = Geo_df.dropna()
Geo_df = polpro_new.Georef.str.split(expand=True)
Geo_df.rename(columns = {0:'Latitude', 1:'Longitude'}, inplace = True)
Geo_df['Latitude'] = Geo_df['Latitude'].str.replace(r'(', '')
Geo_df['Latitude'] = Geo_df['Latitude'].str.replace(r',', '')
Geo_df['Longitude'] = Geo_df['Longitude'].str.replace(r')', '')
New_df = pd.concat([polpro_new, Geo_df], axis=1, join='inner', sort=False)
clabsi1 = New_df[(New_df['Indicator Name']==
'CLABSI Overall Standardized Infection Ratio')]
clabsi_2008 = clabsi1[(clabsi1['Year']== 2008)]
df08 = pd.DataFrame([Point(xy) for xy in zip(clabsi_2008.loc[:,
'Longitude'].astype(float), clabsi_2008.loc[:,'Latitude'].astype(float))])
df08.rename(columns = {0:'geometry'}, inplace = True)
clabsi_08 = clabsi_2008.reset_index()
df08.reset_index()
New_df_08 = pd.concat([clabsi_08, df08], axis=1, sort=False)
New_df_08['IO_to_IP'] = New_df_08['Infections Observed']/New_df_08
['Infections Predicted']
我使用 'coords' DataFrame 创建一个 GeoDataFrame
coords = New_df_08[['IO_to_IP', 'geometry']]
geo_df = gp.GeoDataFrame(coords, crs = 3857, geometry = New_df_08['geometry'])
以下是我尝试在底图上绘制地理参考数据的两种方法
y_plot = geo_df.plot(column='IO_to_IP', figsize=(10,10), alpha=0.5, edgecolor='k')
ctx.add_basemap(ny_plot)
ny_plot
和
geo_df.plot('IO_to_IP', ax=ax)
plt.show()
plt.savefig("my_plot")
我能够创建 ny_plot 但没有基础图,出现此错误:
HTTPError:平铺 URL 导致 404 错误。仔细检查您的瓷砖网址: https ://stamen-tiles-aassl.fastly.net/terrain/24/8388574/8388589.png
这里可能有什么问题?我该如何修复它?
同样,我正在寻找的输出是纽约州底图上的感染率(观察/预测)的等值线图