首页 > 解决方案 > OsmNx:SVG 和 PNG 图像具有不同的比例

问题描述

我在 Jupyter 工作,不明白为什么OsmNx以不同的比例保存SVGPNG 。
我尝试更改 DPI 并调整其他参数,但没有解决问题。
我在在线文档和一些教程中一无所获。

这是一个精简的工作代码:

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")

正确更改distance SVG缩放。
相反, PNG达到最大尺寸,然后被裁剪。

在我的项目中, PNG后来被矢量化。我想根据道路类型保持不同的道路厚度。
这就是我使用plot_figure_ground(可以接受参数street_widths)而不是plot_graph(以相同厚度渲染所有道路)的原因。

在这张图片中,您可以看到这种效果(SVG白色背景,PNG黄色背景):

图片

我究竟做错了什么?

标签: pythonosmnx

解决方案


在这里回答:

这不是 SVG 与 PNG 的问题,但归结为您使用了两种不同的绘图函数,目的非常不同(plot_graph 与 plot_figure_ground)。只需将 dist 参数传递给 plot_figure_ground 即可覆盖其 805 米默认参数化。它在文档中有所描述:https ://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.plot.plot_figure_ground


推荐阅读