Skip to content

fix mpl 3.11#851

Open
ahuang11 wants to merge 2 commits into
mainfrom
fix_mpl_311
Open

fix mpl 3.11#851
ahuang11 wants to merge 2 commits into
mainfrom
fix_mpl_311

Conversation

@ahuang11

@ahuang11 ahuang11 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Description

Fixes #850

I fixed a crash on matplotlib 3.11 where a PlateCarree or Mercator plot (also the default projection when features=[...] is passed) rendered blank on its own and raised ValueError: figure size must be positive finite not [ 8. nan] inside a layout. For these two projections GeoViews hides the native x/y axis and draws cartopy gridliner labels instead, and on matplotlib 3.11 Axes._update_title_position computes a non-finite title y for such a hidden-axis GeoAxes, which then propagates through Axes.get_tightbbox into the HoloViews layout sizing and makes the figure size NaN. I freeze the title auto-position with axis._autotitlepos = False in the gridlabels path, gated on matplotlib >= 3.11 through a new MPL_GE_3_11_0 flag in geoviews.util, so the title keeps its finite default location and the earlier behavior is restored. Other projections, matplotlib < 3.11, and the bokeh backend were never affected.

How to test:

import numpy as np, cartopy.crs as ccrs
import geopandas as gpd, geoviews as gv, hvplot.pandas  # noqa
from shapely.geometry import Polygon

gv.extension('matplotlib')
lon = np.linspace(-170, 170, 11); lat = np.linspace(-80, 80, 6)
polys, vals = [], []
for i in range(len(lat) - 1):
    for j in range(len(lon) - 1):
        polys.append(Polygon([(lon[j], lat[i]), (lon[j+1], lat[i]),
                              (lon[j+1], lat[i+1]), (lon[j], lat[i+1])]))
        vals.append(i * 2 + j)
gdf = gpd.GeoDataFrame({'value': np.array(vals)}, geometry=polys, crs='EPSG:4326')
plot = lambda **kw: gdf.hvplot.polygons(color='value', cmap='viridis', **kw)

plot(features=['coastline'])
(plot(projection=ccrs.PlateCarree(), title='PlateCarree')
 + plot(projection=ccrs.Robinson(), title='Robinson'))

AI Disclosure

Tool & Model:
Usage:

  • I have tested all AI-generated content in my PR.
  • I take responsibility for all AI-generated content in my PR.

Checklist

  • Tests added and are passing
  • Added documentation

@ahuang11 ahuang11 requested a review from hoxbro July 13, 2026 22:02
@ahuang11

Copy link
Copy Markdown
Collaborator Author
image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mercator and PlateCarree projections, and default features=[...], broken on matplotlib 3.11.0

1 participant