问题描述
我正在使用OSMnx回购页面上的示例页面中所示的示例“ make_plot”函数来生成建筑物占地面积的地图。输出为正方形图像,是否可以通过任何方式调整高度和宽度以生成矩形文件?
我对示例进行了一些更改,以使用几何模块而不是已弃用的封装:
def make_plot(place,point,dist,network_type='all',bldg_color='#FF0000',dpi=300,default_width=1,street_widths = {
"footway": 0.5,"steps": 0.5,"pedestrian": 0.5,"service": 0.5,"path": 0.5,"track": 0.5,"primary": 0.5,"secondary": 0.5,"trunk": 1,"motorway": 2,}):
gdf = ox.geometries.geometries_from_point(center_point=point,tags={'building':True},dist=dist)
fig,ax = ox.plot_figure_ground(point=point,dist=dist,network_type=network_type,default_width=default_width,street_widths=street_widths,save=False,show=False,close=True,bgcolor='#343434')
fig,ax = ox.plot.plot_footprints(gdf,ax=ax,color=bldg_color,save=True,filepath="images/{}.png".format(place),dpi=dpi)
make_plot(位置,点,距离)
解决方法
输出为正方形图像,有什么方法可以调整高度和宽度以生成矩形文件吗?
您正在查询一个正方形区域,因此您的结果图相应地为正方形。如果查询非正方形区域,则会得到非正方形图:
import osmnx as ox
ox.config(use_cache=True,log_console=True)
gdf = ox.geometries_from_place('Piedmont,CA,USA',tags={'building':True})
fig,ax = ox.plot_footprints(gdf)
请注意,您得到了fig,ax
的回报,当然可以通过usual matplotlib的方式来调整图形的大小:fig.set_size_inches(9,3)
。请注意,这会调整图形的大小,而不是拉伸(例如,从正方形变为矩形)。另请注意,所有OSMnx绘图函数均采用可选的figsize
参数。参见the documentation。
我对示例进行了一些更改,以使用几何模块而不是已弃用的封装
examples是在一个月前OSMnx v0.16.0发布时更新的,以反映新的geometries
模块。然后,对不推荐使用的footprints
模块的所有引用也将被删除。