From aceb593041aec47223390af5215f53c060e956e6 Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Tue, 27 Jan 2026 14:11:40 +0100 Subject: [PATCH 1/5] Add support for WCS axes Skip WCS axes artist since it's a placeholder with no visible content --- src/matplot2tikz/_save.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/matplot2tikz/_save.py b/src/matplot2tikz/_save.py index 0bb0c1c2..5159680a 100644 --- a/src/matplot2tikz/_save.py +++ b/src/matplot2tikz/_save.py @@ -391,6 +391,10 @@ def _recurse(data: TikzData, obj: Artist) -> list: if isinstance(child, (Spine, XAxis, YAxis)): continue + # Skip WCS axes artist - it's a placeholder with no visible content + if type(child).__name__ == "_WCSAxesArtist": + continue + if isinstance(child, Axes): _process_axes(data, child, content) From 4513f72870b07903ef0509fb040ade38786ec68c Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Tue, 27 Jan 2026 14:12:52 +0100 Subject: [PATCH 2/5] Add astropy to test extras --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 751c9d41..0bce8620 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,6 +44,7 @@ test = [ "coverage[toml]>=7.0.0", "typeguard>=4.4.0", "pandas", + "astropy" ] dev = [ "tox", From f2cdaf7af2673f2478b4f2f32034046377a32536 Mon Sep 17 00:00:00 2001 From: Michele Peresano Date: Tue, 27 Jan 2026 14:13:10 +0100 Subject: [PATCH 3/5] Add unit test for WCS axes --- tests/test_wcs_axes.py | 71 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/test_wcs_axes.py diff --git a/tests/test_wcs_axes.py b/tests/test_wcs_axes.py new file mode 100644 index 00000000..2a460481 --- /dev/null +++ b/tests/test_wcs_axes.py @@ -0,0 +1,71 @@ +"""Test plot with WCS axes.""" + +import warnings + +try: + import astropy + from astropy.wcs import WCS + + HAS_ASTROPY = True +except ImportError: + HAS_ASTROPY = False + +import matplot2tikz +import matplotlib as mpl +import matplotlib.pyplot as plt +import numpy as np +import pytest +from matplotlib.figure import Figure + +mpl.use("Agg") + + +@pytest.mark.skipif(not HAS_ASTROPY, reason="astropy is not installed") +def test_wcs_axes() -> None: + """Test that WCS axes are handled without warnings.""" + # Create a simple WCS + wcs = WCS(naxis=2) + wcs.wcs.crpix = [50, 50] + wcs.wcs.cdelt = [0.1, 0.1] + wcs.wcs.crval = [0, -90] + wcs.wcs.ctype = ["RA---TAN", "DEC--TAN"] + + # Create a figure with WCS projection + fig, ax = plt.subplots(subplot_kw={"projection": wcs}) + + # Add some data + rng = np.random.default_rng(1337) + data = rng.integers(5, size=(2, 4)) + vmin = data.min() + vmax = data.max() + mappable = ax.imshow(data, vmin=vmin, vmax=vmax, origin="lower", cmap="viridis") + ax.grid(color="white", ls="solid", alpha=0.5) + ax.set(xlabel="Galactic Longitude", ylabel="Galactic Latitude") + _ = fig.colorbar(mappable, ax=ax, label="Test Unit") + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + tikz_code = matplot2tikz.get_tikz_code() + + # Filter warnings to only check for the specific warning about unknown objects + unknown_object_warnings = [ + warning + for warning in w + if issubclass(warning.category, UserWarning) + and "Don't know how to handle object" in str(warning.message) + and "_WCSAxesArtist" in str(warning.message) + ] + + # Assert that we didn't get the _WCSAxesArtist warning + assert len(unknown_object_warnings) == 0, ( + f"Got unexpected warning about _WCSAxesArtist: " + f"{[str(warning.message) for warning in unknown_object_warnings]}" + ) + + # Basic checks that the output looks reasonable + assert "\\begin{tikzpicture}" in tikz_code + assert "\\end{tikzpicture}" in tikz_code + # Check that image is included + assert "\\addplot graphics" in tikz_code + + plt.close("all") From 5737c88207023174af8848b471de5ae7dd522146 Mon Sep 17 00:00:00 2001 From: Erwin de Gelder Date: Tue, 3 Feb 2026 10:52:28 +0100 Subject: [PATCH 4/5] Make sure WCSAxes is tested by adding astropy to the required packages. --- requirements-310.txt | 11 +++++++++++ requirements-311.txt | 11 +++++++++++ requirements-312.txt | 11 +++++++++++ requirements-313.txt | 11 +++++++++++ requirements-314.txt | 11 +++++++++++ tests/test_wcs_axes.py | 15 +++------------ 6 files changed, 58 insertions(+), 12 deletions(-) diff --git a/requirements-310.txt b/requirements-310.txt index dd0468aa..eb9593cf 100644 --- a/requirements-310.txt +++ b/requirements-310.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --extra test --resolution highest --python 3.10 -o requirements-310.txt +astropy==6.1.7 + # via matplot2tikz (pyproject.toml) +astropy-iers-data==0.2026.2.2.0.48.1 + # via astropy colorama==0.4.6 # via pytest contourpy==1.3.2 @@ -23,11 +27,14 @@ matplotlib==3.10.7 numpy==2.2.6 # via # matplot2tikz (pyproject.toml) + # astropy # contourpy # matplotlib # pandas + # pyerfa packaging==25.0 # via + # astropy # matplotlib # pytest pandas==2.3.3 @@ -40,6 +47,8 @@ pluggy==1.6.0 # via # pytest # pytest-cov +pyerfa==2.0.1.5 + # via astropy pygments==2.19.2 # via pytest pyparsing==3.2.5 @@ -56,6 +65,8 @@ python-dateutil==2.9.0.post0 # pandas pytz==2025.2 # via pandas +pyyaml==6.0.3 + # via astropy six==1.17.0 # via python-dateutil tomli==2.3.0 diff --git a/requirements-311.txt b/requirements-311.txt index eb35d360..96bfeab8 100644 --- a/requirements-311.txt +++ b/requirements-311.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --extra test --resolution highest --python 3.11 -o requirements-311.txt +astropy==7.2.0 + # via matplot2tikz (pyproject.toml) +astropy-iers-data==0.2026.2.2.0.48.1 + # via astropy colorama==0.4.6 # via pytest contourpy==1.3.3 @@ -21,11 +25,14 @@ matplotlib==3.10.7 numpy==2.3.4 # via # matplot2tikz (pyproject.toml) + # astropy # contourpy # matplotlib # pandas + # pyerfa packaging==25.0 # via + # astropy # matplotlib # pytest pandas==2.3.3 @@ -38,6 +45,8 @@ pluggy==1.6.0 # via # pytest # pytest-cov +pyerfa==2.0.1.5 + # via astropy pygments==2.19.2 # via pytest pyparsing==3.2.5 @@ -54,6 +63,8 @@ python-dateutil==2.9.0.post0 # pandas pytz==2025.2 # via pandas +pyyaml==6.0.3 + # via astropy six==1.17.0 # via python-dateutil tomli==2.3.0 diff --git a/requirements-312.txt b/requirements-312.txt index b9e56f36..4aa7e6fa 100644 --- a/requirements-312.txt +++ b/requirements-312.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --extra test --resolution highest --python 3.12 -o requirements-312.txt +astropy==7.2.0 + # via matplot2tikz (pyproject.toml) +astropy-iers-data==0.2026.2.2.0.48.1 + # via astropy colorama==0.4.6 # via pytest contourpy==1.3.3 @@ -21,11 +25,14 @@ matplotlib==3.10.7 numpy==2.3.4 # via # matplot2tikz (pyproject.toml) + # astropy # contourpy # matplotlib # pandas + # pyerfa packaging==25.0 # via + # astropy # matplotlib # pytest pandas==2.3.3 @@ -38,6 +45,8 @@ pluggy==1.6.0 # via # pytest # pytest-cov +pyerfa==2.0.1.5 + # via astropy pygments==2.19.2 # via pytest pyparsing==3.2.5 @@ -54,6 +63,8 @@ python-dateutil==2.9.0.post0 # pandas pytz==2025.2 # via pandas +pyyaml==6.0.3 + # via astropy six==1.17.0 # via python-dateutil typeguard==4.4.4 diff --git a/requirements-313.txt b/requirements-313.txt index 6f103024..f3243b5a 100644 --- a/requirements-313.txt +++ b/requirements-313.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --extra test --resolution highest --python 3.13 -o requirements-313.txt +astropy==7.2.0 + # via matplot2tikz (pyproject.toml) +astropy-iers-data==0.2026.2.2.0.48.1 + # via astropy colorama==0.4.6 # via pytest contourpy==1.3.3 @@ -21,11 +25,14 @@ matplotlib==3.10.7 numpy==2.3.4 # via # matplot2tikz (pyproject.toml) + # astropy # contourpy # matplotlib # pandas + # pyerfa packaging==25.0 # via + # astropy # matplotlib # pytest pandas==2.3.3 @@ -38,6 +45,8 @@ pluggy==1.6.0 # via # pytest # pytest-cov +pyerfa==2.0.1.5 + # via astropy pygments==2.19.2 # via pytest pyparsing==3.2.5 @@ -54,6 +63,8 @@ python-dateutil==2.9.0.post0 # pandas pytz==2025.2 # via pandas +pyyaml==6.0.3 + # via astropy six==1.17.0 # via python-dateutil typeguard==4.4.4 diff --git a/requirements-314.txt b/requirements-314.txt index 8bc4d7df..56d3b797 100644 --- a/requirements-314.txt +++ b/requirements-314.txt @@ -1,5 +1,9 @@ # This file was autogenerated by uv via the following command: # uv pip compile pyproject.toml --extra test --resolution highest --python 3.14 -o requirements-314.txt +astropy==7.2.0 + # via matplot2tikz (pyproject.toml) +astropy-iers-data==0.2026.2.2.0.48.1 + # via astropy colorama==0.4.6 # via pytest contourpy==1.3.3 @@ -21,11 +25,14 @@ matplotlib==3.10.7 numpy==2.3.4 # via # matplot2tikz (pyproject.toml) + # astropy # contourpy # matplotlib # pandas + # pyerfa packaging==25.0 # via + # astropy # matplotlib # pytest pandas==2.3.3 @@ -38,6 +45,8 @@ pluggy==1.6.0 # via # pytest # pytest-cov +pyerfa==2.0.1.5 + # via astropy pygments==2.19.2 # via pytest pyparsing==3.2.5 @@ -54,6 +63,8 @@ python-dateutil==2.9.0.post0 # pandas pytz==2025.2 # via pandas +pyyaml==6.0.3 + # via astropy six==1.17.0 # via python-dateutil typeguard==4.4.4 diff --git a/tests/test_wcs_axes.py b/tests/test_wcs_axes.py index 2a460481..844f9046 100644 --- a/tests/test_wcs_axes.py +++ b/tests/test_wcs_axes.py @@ -2,25 +2,16 @@ import warnings -try: - import astropy - from astropy.wcs import WCS - - HAS_ASTROPY = True -except ImportError: - HAS_ASTROPY = False - -import matplot2tikz import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np -import pytest -from matplotlib.figure import Figure +from astropy.wcs import WCS + +import matplot2tikz mpl.use("Agg") -@pytest.mark.skipif(not HAS_ASTROPY, reason="astropy is not installed") def test_wcs_axes() -> None: """Test that WCS axes are handled without warnings.""" # Create a simple WCS From f92a6be985900e1e709dfc2388a87af236ea86c3 Mon Sep 17 00:00:00 2001 From: Erwin de Gelder Date: Tue, 3 Feb 2026 11:13:13 +0100 Subject: [PATCH 5/5] Bump version. --- src/matplot2tikz/__about__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matplot2tikz/__about__.py b/src/matplot2tikz/__about__.py index 2116ce92..05396b0c 100644 --- a/src/matplot2tikz/__about__.py +++ b/src/matplot2tikz/__about__.py @@ -1,3 +1,3 @@ """Version number.""" -__version__ = "0.5.1" +__version__ = "0.5.2"