Search code examples
pythonmatplotlibcartopy

How do I get smooth gridlines in cartopy polar stereographic plots with matplotlib?


When plotting with matplotlib and cartopy's NorthPolarStereo projection, the constant-latitude gridlines (parallels) are not smooth circles.

Here is a minimum working example:

from matplotlib import pyplot
import cartopy.crs

ax = pyplot.axes(projection=cartopy.crs.NorthPolarStereo())
ax.set_extent((-180, 180, 60, 90), crs=cartopy.crs.PlateCarree())
ax.gridlines()

pyplot.show()

enter image description here

As you can see, the parallels are a series of straight-line segments between points. There aren't enough points along each line to make them appear smooth. How can I make the parallels more circular?


Solution

  • Q: How can I make the parallels more circular?

    A: You need larger value of n_steps property of the gridliner object created by gridlines(). Its default value is 30. Here is the relevant code that sets the value to 90, and generates better plot.

    gl = ax.gridlines(draw_labels=False, xlocs=None, ylocs=None)
    gl.n_steps = 90
    

    See reference here.

    Sample output:

    enter image description here