python - OsmNx:SVG 和 PNG 图像具有不同的比例
问题描述
我在 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黄色背景):
我究竟做错了什么?
解决方案
在这里回答:
这不是 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
推荐阅读
- sql-server - SQL Query中如何根据其最左侧的String值是数字来确定和避免记录?
- javascript - Mongoose:更新数组内的嵌套数组
- android - 以编程方式设置后获取android视图按钮的宽度
- java - Visual Studio Code Java JUnit 未输出到控制台
- c# - 我该如何解决这个错误“System.ServiceModel.FaultException”
- excel - 如何基于多个选项卡相关值进行嵌套搜索?
- r - Cut by day 省略了年初和年末的日子
- bash - 如何按特定顺序提取行
- apache-spark - Pickle 对象(模型数据)在 SPARK 流中遇到内存问题
- python - 如何在 Python 3 的 .txt 文件中找到单词的位置