我一直在使用OSMNX从开放街道地图中提取公园的形状。我试图将它们显示为标准的pyplot子图,但我不能完全使其直接工作。
说这是我的很多地方:
places =
{'Hyde Park' : 'Hyde Park, London, UK',
'Kensington Gardens' : 'Kensington Gardens, London, UK',
'Regents Park' : 'Regents Park, London, UK',
'Hampstead Heath' : 'Hampstead Heath, London, UK',
'Alexandra Park' : 'Alexandra Park, London, UK',
'Clissold Park' : 'Clissold Park, London, UK',
'Finsbury Park' : 'Finsbury Park, N4 2NQ, London, UK',
'Russell Square' : 'Russell Square, London, UK'
}
以下正确显示了堆叠的形状:
for place in sorted(places.keys()):
query = places[place]
print(query)
G = ox.gdf_from_place(query)
fig, ax = ox.plot_shape(G)
我不是pyplot / OSMNX的专家,但我了解的是,为了将形状图传递到子图,我需要以某种方式“提取轴”。
但是,我知道如何绘制形状,将其转换为shapefile,并在子图中显示它:
import shapefile
n = len(places)
ncols = int(np.ceil(np.sqrt(n)))
nrows = int(np.ceil(n / ncols))
figsize = (ncols * 3, nrows * 3)
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, subplot_kw, {'projection':None})
axes = [item for sublist in axes for item in sublist]
for ax, place in zip(axes, sorted(places.keys())):
query = places[place]
G = ox.gdf_from_place(query)
ox.save_gdf_shapefile(G, folder='shp', filename=place)
shp = shapefile.Reader("shp/"+place+"/"+place+".shp")
for shape in shp.shapeRecords():
x = [i[0] for i in shape.shape.points[:]]
y = [i[1] for i in shape.shape.points[:]]
ax.plot(x,y)
是否可以直接使用plot_shape()生成相同的图表?
答案 0 :(得分:1)
根据您的最终目标是几个选择:
// related posts - don't show posts earlier than January 1 2017
function jetpackme_exclude_related_post($exclude_post_ids, $post_id ) {`
$args = array(
'date_query' => array(
'before' => 2017-01-01,
'inclusive' => true,
),
'posts_per_page' => '99999',
'fields' => 'ids'
);
$query = new WP_Query($args);
if ($query->have_posts()):
foreach($query->posts as $id ):
$exclude_post_ids[] = $id;
endforeach;
endif;
return $exclude_post_ids;
}
add_filter( 'jetpack_relatedposts_filter_exclude_post_ids',
'jetpackme_exclude_related_post', 20, 2 );