HTTPError:图块URL导致404错误

时间:2019-12-07 17:24:34

标签: python pandas matplotlib contextily

我有纽约州立医院的地理参考数据,并想用基础地图创建一个choropleth地图。我也尝试使用.plot()进行分层,但没有成功。 当我运行分层图的代码时,没有图像显示,而上下文运行时,出现以下错误消息:

HTTPError:图块URL导致404错误。仔细检查您的图块网址: https://stamen-tiles-a.a.ssl.fastly.net/terrain/24/8388574/8388589.png

conda环境:

*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

上述步骤效果很好,并创建了一张漂亮的地图。以下是我如何处理纽约州立医院的数据以创建make GeoDataFrame和值的choropleth图(观察到的感染/预测到的感染)

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”数据框来创建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-a.a.ssl.fastly.net/terrain/24/8388574/8388589.png

这里可能是什么问题?我该如何解决?

同样,我要寻找的输出是在纽约州基础图上的感染率(观测/预测)的彩色图

0 个答案:

没有答案