OsmNx:SVG 和 PNG 图像具有不同的比例
OsmNx: SVG and PNG images have a different scale
我在 Jupyter 工作,不明白为什么 OsmNx 保存 SVG 和 PNG 具有不同的尺度。
我尝试更改 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 黄色背景):
我做错了什么?
已回答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
我在 Jupyter 工作,不明白为什么 OsmNx 保存 SVG 和 PNG 具有不同的尺度。
我尝试更改 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 黄色背景):
我做错了什么?
已回答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