0

I'm using the sample "make_plot" function shown in the example page on the OSMnx repo page to generate maps of building footprints. The output is a square image, is there any way to adjust the height and width to produce a rectangular file?

I made some changes to the example to use the geometries module instead of the deprecated footprints:

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, show=False, close=True, filepath="images/{}.png".format(place), dpi=dpi)

make_plot(place, point, dist)

tykom
  • 35
  • 9

1 Answers1

1

The output is a square image, is there any way to adjust the height and width to produce a rectangular file?

You are querying a square area, so your plot of the results is correspondingly square. If you query a non-square area, you get a non-square 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)

rectangular plot

Note that you get a fig, ax back, and you can of course resize your figure the usual matplotlib way: fig.set_size_inches(9, 3). Note that this resizes your figure rather than stretch it (e.g., from a square to a rectangle). Also note that all OSMnx plotting functions take an optional figsize argument. See the documentation.

I made some changes to the example to use the geometries module instead of the deprecated footprints

The examples were updated a month ago when OSMnx v0.16.0 was released, to reflect the new geometries module. Any references to the deprecated footprints module were removed then as well.

gboeing
  • 5,691
  • 2
  • 15
  • 41
  • Thank you, I will try that. I didn't adjust figsize because the docstring under the plot_figure_ground function in plot.py said: "figsize : numeric (width, height) of figure, should be equal". I'll try messing with it though – tykom Oct 03 '20 at 01:16
  • 1
    That specific helper function exists to create square plots by querying square areas. If you don't want a square study area, don't use that helper function. – gboeing Oct 03 '20 at 01:27
  • Turns out I was looking at the examples from 0.11 for some reason. I appreciate your help, osmnx is an incredible package – tykom Oct 03 '20 at 05:07
  • I used the updates helper function in the example you linked and the footprints do not fill the image completely, there is a small border around the edge of the map. How can I generate maps where the footprints and roads fill the entire image? – tykom Oct 03 '20 at 15:06
  • Here are two examples, same map, different distances: [Example 1](https://imgur.com/QGAShPf) [Example 2](https://imgur.com/FJuVl5a) – tykom Oct 03 '20 at 15:19