Matplotlib底图:避免文本重叠

时间:2017-04-14 15:25:22

标签: python matplotlib matplotlib-basemap

我正在使用 Matplotlib Basemap 绘制地图并标有标签:

RecyclerView

我在密集区域获得了大量重叠标签。有没有办法防止标签重叠?

1 个答案:

答案 0 :(得分:1)

我能想到的唯一方法是

  1. 调整文本打印开始的距离(指定为10)
  2. 放大地图,同时显示标记点
  3. 第2点的粗略例子

    Full view Map

    further Zoom High Zoom

    from mpl_toolkits.basemap import Basemap
    import matplotlib.pyplot as plt
    m = Basemap(width=120000,height=90000,projection='aeqd',
                resolution=None,lat_0=30.,lon_0=80.)
    lats=[30.0,30.1,30.2,30.0,30.1,30.2]
    lons=[80.0,80.1,80.2,80.3,80.4,80.5]
    m.bluemarble()
    x, y = m(lons,lats)
    labels=['Point1','Point2','Point3','Point4','Point5','Point6']
    m.scatter(x,y,10,marker='o',color='k')
    for label, xpt, ypt in zip(labels, x, y):
        plt.text(xpt + 10, ypt + 10, label, size=20)
    plt.show()