[Python] Basemap plots in Matplotlib have cutoff map boundary lines

Discussão em 'Python' iniciado por Stack, Abril 21, 2025.

  1. Stack

    Stack Membro Participativo

    When trying to create a grid of maps in matplotlib using the Basemap toolkit, I noticed that the line that bounds the map projection is cut off on all four sides.

    Look at the following minimal example where each panel clearly shows that the black line circling around each map has nonuniform thickness as if it's being cut off by the axes bounds:

    import matplotlib as mpl
    from matplotlib import pyplot as plt
    import mpl_toolkits.basemap as basemap

    fig = plt.figure(figsize=(7,4))
    gs = fig.add_gridspec(1, 1)
    gs01 = gs0[0].subgridspec(3, 3)

    for i in range(3):
    for j in range(3):
    ax = fig.add_subplot(gs01[i,j])

    m = basemap.Basemap(projection="kav7", lon_0=0, resolution="c", ax=ax)
    m.fillcontinents(color="#c3c3c3", lake_color="white")
    m.drawcountries(color="#939393")


    image of nine maps arranged in a grid produced by the plot above, each showing the cutoff issue

    I also then noticed that a similar issue is present even in the [official user guide.] 2 Is there away to address this? It doesn't seem to me like there is an option in basemap that would control this. I think it is caused by trying to plot as big a map as possible within the Axes bounds, and the thickness of the map boundary line is not accounted in this calculation. Does anyone know of a matplotlib option remedy this? Axes.margins does not do anything in this situation. Thanks!

    Continue reading...

Compartilhe esta Página