简化下列代码:gdf = gpd.read_file("shanghai_districts.shp") lis_time=['0:00-4:00','4:00-8:00','8:00-12:00','12:00-16:00','16:00-20:00','20:00-24:00','次日0:00-4:00'] j1=0 for i in (df.groupby(pd.Grouper(key='stime', freq='4H'))): data_r=i[1] gdf_points = gpd.GeoDataFrame(data_r, geometry=gpd.points_from_xy(data_r['gcj_s_lng'], data_r['gcj_s_lat'])) plt.figure(figsize=(10,10)) ax = gdf.plot(color='white',edgecolor='k',linewidth=0.3) gdf_points.plot(ax=ax, column=None, cmap='Oranges', scheme='quantiles', k=5, alpha=0.9, markersize=0.01) plt.yticks([30.8,31.0,31.2,31.4,31.6,31.8],['30.8°N','31.0°N','31.2°N','31.4°N','31.6°N','31.8°N'],fontsize=12) plt.xticks([120.8,121.0,121.2,121.4,121.6,121.8,122.0,122.2],['120.8°E','121.0°E','121.2°E','121.4°E','121.6°E','121.8°E','122.0°E','122.2°E'],fontsize=12,rotation=45) plt.title(lis_time[j1]+'时间段内出发订单数量分布') plt.show() j1=j1+1 j1=0 for i in (df.groupby(pd.Grouper(key='etime', freq='4H'))): data_r=i[1] gdf_points = gpd.GeoDataFrame(data_r, geometry=gpd.points_from_xy(data_r['gcj_e_lng'], data_r['gcj_e_lat'])) plt.figure(figsize=(10,10)) ax = gdf.plot(color='white',edgecolor='k',linewidth=0.3) gdf_points.plot(ax=ax, column=None, cmap='Oranges', scheme='quantiles', k=5, alpha=0.9, markersize=0.01) plt.yticks([30.8,31.0,31.2,31.4,31.6,31.8],['30.8°N','31.0°N','31.2°N','31.4°N','31.6°N','31.8°N'],fontsize=12) plt.xticks([120.8,121.0,121.2,121.4,121.6,121.8,122.0,122.2],['120.8°E','121.0°E','121.2°E','121.4°E','121.6°E','121.8°E','122.0°E','122.2°E'],fontsize=12,rotation=45) plt.title(lis_time[j1]+'时间段内到达订单数量分布') plt.show() j1=j1+1
时间: 2023-06-12 15:04:49 浏览: 211
vhdl.rar_fun_graf.gdf_vhdl编写的
gdf = gpd.read_file("shanghai_districts.shp")
lis_time=['0:00-4:00','4:00-8:00','8:00-12:00','12:00-16:00','16:00-20:00','20:00-24:00','次日0:00-4:00']
for time_key in ['stime', 'etime']:
j1 = 0
for i in (df.groupby(pd.Grouper(key=time_key, freq='4H'))):
data_r = i[1]
if time_key == 'stime':
gdf_points = gpd.GeoDataFrame(data_r, geometry=gpd.points_from_xy(data_r['gcj_s_lng'], data_r['gcj_s_lat']))
title = '时间段内出发订单数量分布'
else:
gdf_points = gpd.GeoDataFrame(data_r, geometry=gpd.points_from_xy(data_r['gcj_e_lng'], data_r['gcj_e_lat']))
title = '时间段内到达订单数量分布'
plt.figure(figsize=(10,10))
ax = gdf.plot(color='white',edgecolor='k',linewidth=0.3)
gdf_points.plot(ax=ax, column=None, cmap='Oranges', scheme='quantiles', k=5, alpha=0.9, markersize=0.01)
plt.yticks([30.8,31.0,31.2,31.4,31.6,31.8],['30.8°N','31.0°N','31.2°N','31.4°N','31.6°N','31.8°N'],fontsize=12)
plt.xticks([120.8,121.0,121.2,121.4,121.6,121.8,122.0,122.2],['120.8°E','121.0°E','121.2°E','121.4°E','121.6°E','121.8°E','122.0°E','122.2°E'],fontsize=12,rotation=45)
plt.title(lis_time[j1] + ' ' + title)
plt.show()
j1 += 1
阅读全文