Skip to content

MapPanel plots correctly with isobars but not isotherms #4192

Closed

Description

@sgdecker

What went wrong?

With the code below, the first figure that pops up looks like this:

Image

Note the lack of Canadian provinces despite the mp.layers setting, as well as the relatively coarse boundaries.

The second figure looks like what I would expect:

Image

As far as I can tell, I'm setting up the MapPanel and PanelContainers the same for both plots, yet the map is different. Is this a bug?

Operating System

Linux

Version

1.7.1

Python Version

3.13.16

Code to Reproduce

import xarray as xr
import metpy.calc as mpcalc
from metpy.cbook import get_test_data
from metpy.plots import ContourPlot, MapPanel, PanelContainer
from metpy.units import units

nam = xr.open_dataset(get_test_data('NAM_test.nc', as_file_obj=False)).metpy.parse_cf()
isen_lev = [300] * units('K')
smooth = 10
hgt = mpcalc.smooth_gaussian(nam['Geopotential_height_isobaric'], smooth).squeeze().rename('hgt')
tmp = mpcalc.smooth_gaussian(nam['Temperature_isobaric'], smooth).squeeze().rename('tmp')
nam_isen = mpcalc.isentropic_interpolation_as_dataset(isen_lev, tmp, hgt,
                                                      bottom_up_search=False)

nam_isen = nam_isen.metpy.assign_latitude_longitude()
lev = nam_isen.isentropic_level.values[0]

cp = ContourPlot()
cp.data = nam_isen
cp.field = 'temperature'
cp.contours = range(100, 400, 10)
cp.clabels = True
cp.plot_units = 'K'

mp = MapPanel()
mp.layers = ['coastline', 'borders', 'states']
mp.layers_edgecolor = 'saddlebrown'
mp.title = f'{lev}-K'
mp.plots = [cp]

pc = PanelContainer()
pc.size = (12,8.5)
pc.panels = [mp]
pc.draw()
pc.figure.tight_layout()
pc.show()

cp = ContourPlot()
cp.data = nam_isen
cp.field = 'pressure'
cp.contours = range(100, 1050, 50)
cp.clabels = True
cp.plot_units = 'hPa'

mp = MapPanel()
mp.layers = ['coastline', 'borders', 'states']
mp.layers_edgecolor = 'saddlebrown'
mp.title = f'{lev}-K'
mp.plots = [cp]

pc = PanelContainer()
pc.size = (12,8.5)
pc.panels = [mp]
pc.draw()
pc.figure.tight_layout()
pc.show()

Errors, Traceback, and Logs

Activity

  1. dcamron commented on Nov 3, 2026

    @dcamron
    Member

    You found yourself right at an odd Cartopy defaults quirk! By default, the named Natural Earth features from Cartopy are filtered through an "auto scaler" setting their scale from coarse to fine based on the extent of the axes. We mirror this explicitly in MapPanel for our named layers, but the default hard cutoff to go from a medium scale to a coarser one is over 50 deg of lat and lon extent. You'll notice that your temperature image is slightly zoomed out with an extent that, surprise, barely grows larger than that 50 deg/each threshold.

    You can verify this by inspecting the extents directly, or just changing your mp.contours values. I tried 9, 15, etc. Or you can just crank up the total number of contours eg mp.contours = 25. Note the extent shrinks and the features pop in. Blame upstream contour autoscaling :)

    You can avoid this by either fixing your extent using mp.area, by name ('uslcc' is close here) or by tuple : (lon_left, lon_right, lat_bottom, lat_top); or by passing in features with specific scales to MapPanel.layers, eg

    import cartopy.feature as cfeature
    
    coastline = cfeature.COASTLINE.with_scale('50m')
    borders = cfeature.BORDERS.with_scale('50m')
    states = cfeature.STATES.with_scale('50m')
    
    ...
    mp.layers = [coastline, borders, states]
    ...

    We might look to make the interface to MapPanel.area a bit cleaner, as it was messy when I was playing around trying to pull lon/lat extents from the DataSet. Or we could take an opinionated approach on the feature scaling on our named features. But otherwise call it luck of the draw()!

    I'll leave this open a bit in case we decide to open any new issue on those points. Thanks for the clear report as ever.

  2. sgdecker commented on Nov 4, 2026

    @sgdecker
    ContributorAuthor

    Hmm, I guess I'm concerned that the extent of the map changes based on the presence or absence of certain contours. I haven't tested this, but I imagine the same plot settings, but at different times, would shift around the map a bit (and therefore cause Canadian provinces to appear or disappear seemingly at random because of the auto-scaler) as the isotherms change from one time to the next. That's not good.

    I'm surprised the map changes at all depending on the contours. I had hoped that not specifying MapPanel.area was equivalent to GEMPAK's GAREA=grid, but evidently this is not the case, and that means #4161 really is a feature request (create a new alias MapPanel.area = 'grid' that does exactly what GEMPAK does, that is, show the entire grid, no more, no less, assuming you leave the projection unspecified) rather than just a documentation update.

  3. dcamron commented on Nov 5, 2026

    @dcamron
    Member

    With that captured in the other issue, I'll close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething is not working like it should

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions