【问题标题】:How to prevent an osmnx figure from being shown in Python (jupyter)如何防止 osmnx 图形在 Python 中显示(jupyter)
【发布时间】:2021-05-24 22:06:20
【问题描述】:

使用matplotlib,我们可以防止使用close函数显示图形

import matplotlib.pyplot as plt

a = range(0,5)
b = range(0,10,2)

plt.plot(a,b, 'r-*')

plt.close()

因为osmnx在后台使用matplotlib,我认为close函数可以以相同的方式使用

import matplotlib.pyplot as plt
import osmnx as ox

graph = ox.graph_from_bbox(41.97278, 41.97614,  -87.73993, -87.73755, network_type='drive')

ox.plot_graph(graph, 
             bbox=[41.97278, 41.97614,  -87.73993, -87.73755], 
              )
plt.close()

不幸的是,这个数字仍然显示出来。
有没有办法阻止显示的数字?
提前致谢。

【问题讨论】:

    标签: python matplotlib jupyter-lab osmnx


    【解决方案1】:

    您是否阅读了有关该功能的 OSMnx documentation

    show (bool) – 如果为 True,则调用 pyplot.show() 显示图形

    close (bool) - 如果为 True,则调用 pyplot.close() 关闭图形

    OSMnx 用法examples 中也演示了这些参数的使用。

    import osmnx as ox
    bbox = 41.97278, 41.97614,  -87.73993, -87.73755
    G = ox.graph_from_bbox(*bbox, network_type='drive')
    fig, ax = ox.plot_graph(G, bbox=bbox, show=False, close=True)
    

    【讨论】:

    • 谢谢@gboeing。我错过了那个参数
    猜你喜欢
    • 2021-04-20
    • 2013-09-14
    • 2018-12-27
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2017-05-28
    • 1970-01-01
    相关资源
    最近更新 更多