Search code examples
pythonmatplotlibgiscartopy

Is there a way to make gridline labels appear on only one set of axes?


I'm making a map using matplotlib.pyplot and I used the gridlines feature to create "labels" on the x and y axis of degrees latitude and longitude. I set the gridlines color to "none" to avoid having the gridlines there. However, these labels appear on each side of the plot and, at one point, coincide with my colorbar. Is there a way I could make these gridline labels only appear on the bottom and left of the plot? I can't find a list of the available kwargs anywhere. This is the code I used:

ax.gridlines(draw_labels=True, color="none")

And here is an image of the map. I would ideally like to remove the degree labels on the right and top axes.

enter image description here


Solution

  • You can achieve what you need with these relevant code:-

    # minor change to the existing line of code
    gls = ax.gridlines(draw_labels=True, color="none")
    
    # other lines of code
    
    # add these before plotting
    gls.top_labels=False   # suppress top labels
    gls.right_labels=False # suppress right labels