0

I am working in Jupyter and don't understand why OsmNx saves SVG and PNG with different scales.
I tried changing DPI and tweaked other parameters, but didn't solve the issue.
I found nothing about it in the online documentation and some tutorials.

This is a stripped-down working code:

import osmnx as ox
import os
from IPython.display import Image

%matplotlib inline
ox.config(log_file=False, log_console=False, use_cache=True)

place = "aPlace"
network_type = "drive"  
location_point = (50.6233696,12.3007474)

G = ox.graph_from_point(
    location_point, 
    distance=1600,  #<============
    distance_type='bbox', 
    network_type="drive", 
    clean_periphery=False, 
)


street_widths = {'footway' : 0.5,
             'steps' : 0.5,
             'pedestrian' : 0.5,
             'path' : 0.5,
             'track' : 0.5,
             'service' : 2,
             'residential' : 3,
             'primary' : 5,
             'motorway' : 6}

ox.plot_graph(G, show=True,node_size=0, edge_linewidth=2, edge_color="#000000", save=True, filename="map1", file_format='svg')
ox.plot_figure_ground(G, street_widths=street_widths, show=True, bgcolor="#ffff00",  edge_color="#000000", save=True, filename="map1", file_format="png")

Changing distance SVG scales properly.
PNG, instead, reaches a maximum size and then it is cropped.

In my project PNG is later vectorialized. I want to keep different road thicknesses according to the road type.
That's why I use plot_figure_ground (that can accept the parameter street_widths), and not plot_graph (that renders all roads with the same thickness).

In this images you can see this effect (SVG white background, PNG yellow background):

images

What am I doing wrong?

Alex Poca
  • 2,406
  • 4
  • 25
  • 47

1 Answers1

1

Answered here:

This isn't an SVG vs PNG issue, but it comes down to the fact that you're using two different plotting functions with very different purposes (plot_graph vs plot_figure_ground). Just pass the dist argument into plot_figure_ground to override its 805-meter default parameterization. It's described in the documentation: https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.plot.plot_figure_ground

gboeing
  • 5,691
  • 2
  • 15
  • 41