我有带地理参考的纽约州医院数据,想要创建一个带底图的等值线地图。我还尝试使用.plot()进行分层,但没有成功。当我运行分层绘图代码时,没有显示任何图像,当我运行contextily时,会出现以下错误信息:
HTTPError: Tile URL resulted in a 404 error. Double-check your tile url: https://stamen-tiles-a.a.ssl.fastly.net/terrain/24/8388574/8388589.png conda环境:
上述步骤很有效,可以创建一个漂亮的地图。下面是我如何操作纽约州医院数据以创建GeoDataFrame和值用于分级色彩地图(观察感染/预测感染)。
我使用“coords”数据框创建了一个GeoDataFrame。
我能够创建ny_plot,但无法创建基础图,出现以下错误:
HTTPError: Tile URL resulted in a 404 error. Double-check your tile url: https://stamen-tiles-a.a.ssl.fastly.net/terrain/24/8388574/8388589.png 这里可能出了什么问题?我该如何解决?
再次说明,我要的输出是一个纽约州底图上感染比率(观察值/预测值)的区域图。
HTTPError: Tile URL resulted in a 404 error. Double-check your tile url: 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
上述步骤很有效,可以创建一个漂亮的地图。下面是我如何操作纽约州医院数据以创建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”数据框创建了一个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: Tile URL resulted in a 404 error. Double-check your tile url: https://stamen-tiles-a.a.ssl.fastly.net/terrain/24/8388574/8388589.png 这里可能出了什么问题?我该如何解决?
再次说明,我要的输出是一个纽约州底图上感染比率(观察值/预测值)的区域图。