You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default values of area and projection for MapPanel objects are undocumented #4161
With the code below, I'm expecting to get a map showing the entire model grid, no more, no less. However, the map extends too far to the east and south:
I'm not sure how to classify it, but it is expected behavior with Cartopy (which is used under the hood). The problem is that the extent that is set needs to be translated rectangle (x range and y range) in the plotted (projected) coordinate system. When you give it an extent in lat/lon, it's going to convert it to a rectangle with 4 points. This geometry is then projected to the destination projection; in this case the destination is Lambert Conformal (conic), so the rectangle becomes a curved conic section like:
To turn this back into plot limits, the bounding box of this shape is taken (in projected coordinates). Essentially the problem is that once you're in projected coordinates, the e.g. right side of the plot is not defined by a single longitude value. That leaves you with the option of having a plot too big (which is what Cartopy does by default), or having a plot too small and clipping data.
Your figure nicely shows why it's the southern and eastern sides that are too large (and also indicates I've lost a few of the northern rows from the grid in my plot).
In this case, I have intentionally set my map projection to match the projection of the grid, so it should be possible in principle to get a map that covers the grid precisely, no more, no less. I'm essentially trying to do what GEMPAK does with GAREA=GRID. However, it looks like I have to solve an inverse problem of sorts (I think I need to determine the lat/lon pairs for the red corners such that the green corners calculated by CartoPy match the corners I really want, i.e., the corners of the actual grid), so I'll do some playing around with using Cartopy/Matplotlib directly to generate the plot, and if I see a reasonable way forward, I'll see if I can come up with a feature/pull request to implement this GAREA=GRID-like functionality in MetPy.
D'oh! I get the plot I want simply by not specifying area and projection at all. The default values for these two traits are what I want. However, the defaults do not appear to be documented, so I am changing this issue to a request for improved docstrings.
changed the title [-]Specifying grid corners for MapPanel area produces larger map than expected[/-][+]Default values of area and projection for MapPanel objects are undocumented[/+]on Oct 22, 2026
Actually, based on #4192 it seems there might be some missing functionality here. Namely, there doesn't seem to be a way to force the map to match the grid exactly, like GAREA = grid does in GEMPAK. Thus, this issue has now evolved into a feature request to make such a MapPanel.area specification possible.
I think this can be achieved with another elif around here, where in the new block the set_extent call would use the min and max map coordinates rather than geographic coords (and the reference to the PlateCarree CRS would be omitted), but I need to test this, for instance with the #4192 test case!
I've been playing around with this this week, and will put something together here. The main behavior decision in front of me: let's say in your example, your barb plot and your contours come from different grids. How does MapPanel.area = 'grid' behave?
For comparison: currently MapPanel.projection = 'data' (the default) just looks at the first plot in the list and uses its CRS (if it exists.) I'm gonna clean that up a bit to at least search for a valid CRS among all plots.
We could force some math to calculate an overlap or take any one (first, largest, whatever) grid of the bunch. Thoughts?
The main behavior decision in front of me: let's say in your example, your barb plot and your contours come from different grids. How does MapPanel.area = 'grid' behave?
That's a good question! I don't have a strong opinion, but I favor something explicit rather than an automatic choice like first or largest, so I'd go with:
It is an error to use MapPanel.area = 'grid' when not all of the grids on the MapPanel are the same, or
Same as (1), but also allow MapPanel.area = (plotting object) where the plotting object is a specific instance of ContourPlot, etc., and it is that grid that is used to specify the area.
Activity
dopplershift commentedon Oct 17, 2026
I'm not sure how to classify it, but it is expected behavior with Cartopy (which is used under the hood). The problem is that the extent that is set needs to be translated rectangle (x range and y range) in the plotted (projected) coordinate system. When you give it an extent in lat/lon, it's going to convert it to a rectangle with 4 points. This geometry is then projected to the destination projection; in this case the destination is Lambert Conformal (conic), so the rectangle becomes a curved conic section like:
To turn this back into plot limits, the bounding box of this shape is taken (in projected coordinates). Essentially the problem is that once you're in projected coordinates, the e.g. right side of the plot is not defined by a single longitude value. That leaves you with the option of having a plot too big (which is what Cartopy does by default), or having a plot too small and clipping data.
sgdecker commentedon Oct 19, 2026
Your figure nicely shows why it's the southern and eastern sides that are too large (and also indicates I've lost a few of the northern rows from the grid in my plot).
In this case, I have intentionally set my map projection to match the projection of the grid, so it should be possible in principle to get a map that covers the grid precisely, no more, no less. I'm essentially trying to do what GEMPAK does with GAREA=GRID. However, it looks like I have to solve an inverse problem of sorts (I think I need to determine the lat/lon pairs for the red corners such that the green corners calculated by CartoPy match the corners I really want, i.e., the corners of the actual grid), so I'll do some playing around with using Cartopy/Matplotlib directly to generate the plot, and if I see a reasonable way forward, I'll see if I can come up with a feature/pull request to implement this GAREA=GRID-like functionality in MetPy.
sgdecker commentedon Oct 22, 2026
D'oh! I get the plot I want simply by not specifying
areaandprojectionat all. The default values for these two traits are what I want. However, the defaults do not appear to be documented, so I am changing this issue to a request for improved docstrings.[-]Specifying grid corners for MapPanel area produces larger map than expected[/-][+]Default values of area and projection for MapPanel objects are undocumented[/+]sgdecker commentedon Nov 4, 2026
Actually, based on #4192 it seems there might be some missing functionality here. Namely, there doesn't seem to be a way to force the map to match the grid exactly, like GAREA = grid does in GEMPAK. Thus, this issue has now evolved into a feature request to make such a
MapPanel.areaspecification possible.I think this can be achieved with another elif around here, where in the new block the
set_extentcall would use the min and max map coordinates rather than geographic coords (and the reference to the PlateCarree CRS would be omitted), but I need to test this, for instance with the #4192 test case!dcamron commentedon Nov 10, 2026
I've been playing around with this this week, and will put something together here. The main behavior decision in front of me: let's say in your example, your barb plot and your contours come from different grids. How does
MapPanel.area = 'grid'behave?For comparison: currently
MapPanel.projection = 'data'(the default) just looks at the first plot in the list and uses its CRS (if it exists.) I'm gonna clean that up a bit to at least search for a valid CRS among all plots.We could force some math to calculate an overlap or take any one (first, largest, whatever) grid of the bunch. Thoughts?
sgdecker commentedon Nov 10, 2026
That's a good question! I don't have a strong opinion, but I favor something explicit rather than an automatic choice like first or largest, so I'd go with:
MapPanel.area = 'grid'when not all of the grids on the MapPanel are the same, orMapPanel.area = (plotting object)where the plotting object is a specific instance of ContourPlot, etc., and it is that grid that is used to specify the area.