Skip to content

Commit e9fe056

Browse files
committed
fix(plot): exclude matplotlib 3.11.0, which crashes faceted plots
Faceted statistics plots with a shared y-axis and scientific offset text crash at draw time on matplotlib 3.11.0 with 'ValueError: cannot convert float NaN to integer'. This is an upstream regression (matplotlib/matplotlib#31881, bisected to matplotlib/matplotlib#31285) fixed by matplotlib/matplotlib#31885 and milestoned for 3.11.1, which is not released yet. Exclude the broken version and add a regression test covering the offset-text faceting scenario.
1 parent 1eb9db0 commit e9fe056

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎docs/release-notes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SPDX-License-Identifier: CC-BY-4.0
2020

2121
### Bug Fixes
2222

23+
- Exclude `matplotlib` 3.11.0, which crashes faceted statistics plots with shared axes and scientific offset text (`ValueError: cannot convert float NaN to integer`, [matplotlib#31881](https://github.com/matplotlib/matplotlib/issues/31881)). The upstream fix lands in matplotlib 3.11.1. (<!-- md:pr 1781 -->)
2324
- Fix [`supply`][pypsa.optimization.expressions.StatisticExpressionsAccessor.supply] and [`withdrawal`][pypsa.optimization.expressions.StatisticExpressionsAccessor.withdrawal] expressions dropping the charging contribution of `StorageUnit` components. The supply/withdrawal split now considers the effective coefficients of the operational variable, so the `p_store` term is correctly reported as a withdrawal. (<!-- md:pr 1760 -->)
2425
- Fix [`n.graph()`][pypsa.network.graph.NetworkGraphMixin.graph] building edges in a non-deterministic order, which could make results that depend on the network's cycles differ between runs. In particular, security-constrained optimization (SCLOPF) now returns consistent results. (<!-- md:pr 1764 -->)
2526

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
"xarray",
3737
"netcdf4",
3838
"linopy>=0.7.0",
39-
"matplotlib",
39+
"matplotlib!=3.11.0", # faceted plots crash on 3.11.0, see matplotlib#31881
4040
"plotly",
4141
"pydeck>=0.6",
4242
"seaborn",

‎test/test_statistics_plot.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,26 @@ def test_collection_of_multi_investment_facets_both_dimensions(ac_dc_network_r,
313313
plt.close(fig)
314314

315315

316+
def test_collection_faceted_plot_with_offset_text(ac_dc_network_r):
317+
"""Faceted plots draw when values are large enough for the axis offset text.
318+
319+
On matplotlib 3.11.0 a faceted figure with a shared y-axis showing the
320+
scientific offset text (e.g. ``1e6``) crashed at draw time with
321+
``ValueError: cannot convert float NaN to integer``
322+
(matplotlib/matplotlib#31881). See #1779.
323+
"""
324+
network = ac_dc_network_r.copy()
325+
network.c.generators.dynamic.p *= 1e6
326+
nc = NetworkCollection(
327+
[network, network.copy()], index=pd.Index(["low", "high"], name="scenario")
328+
)
329+
330+
fig, ax, g = nc.statistics.supply.plot.area(color="carrier")
331+
fig.canvas.draw()
332+
333+
plt.close(fig)
334+
335+
316336
def test_networks_plot_map(network_collection):
317337
with pytest.raises(NotImplementedError):
318338
network_collection.statistics.energy_balance.plot.map()

0 commit comments

Comments
 (0)