Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

Closes #434

Fix an issue where the indexing is using unequal slices.

@cvanelteren cvanelteren enabled auto-merge (squash) December 17, 2025 20:49
@cvanelteren cvanelteren disabled auto-merge December 17, 2025 20:50
@cvanelteren cvanelteren enabled auto-merge (squash) December 17, 2025 20:50
@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/gridspec.py 66.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren cvanelteren merged commit 6e0f5c1 into main Dec 17, 2025
24 of 25 checks passed
@cvanelteren cvanelteren deleted the fix-slicing-grid branch December 17, 2025 22:05
cvanelteren added a commit that referenced this pull request Dec 18, 2025
cvanelteren added a commit that referenced this pull request Dec 29, 2025
* Fix GeoAxes panel alignment with aspect-constrained projections

Add _adjust_panel_positions() method to dynamically reposition panels after apply_aspect() shrinks the main GeoAxes to maintain projection aspect ratio. This ensures panels properly flank the visible map boundaries rather than remaining at their original gridspec positions, eliminating gaps between panels and the map when using large pad values or when the projection's aspect ratio differs significantly from the allocated subplot space.

* Fix double-adjustment issue in panel positioning

Remove _adjust_panel_positions() call from GeoAxes.draw() to prevent
double-adjustment. The method should only be called in
_CartopyAxes.get_tightbbox() where apply_aspect() happens and tight
layout calculations occur. This fixes the odd gap issue when saving
figures with top panels.

* Revert "Fix double-adjustment issue in panel positioning"

This reverts commit ef55f69.

* Fix panel gap calculation to use original positions

Use panel.get_position(original=True) instead of get_position() to
ensure gap calculations are based on original gridspec positions,
not previously adjusted positions. This makes _adjust_panel_positions()
idempotent and fixes accumulated adjustment errors when called multiple
times during the render/save cycle.

* Adjust tolerance in test_reference_aspect for floating-point precision

The reference width calculations have minor floating-point precision
differences (< 0.1%) which are expected. Update np.isclose() to use
rtol=1e-3 to account for this while still validating accuracy.

* Fix boundary label visibility issue in cartopy

Cartopy was hiding boundary labels due to floating point precision issues
when checking if labels are within the axes extent. The labels at exact
boundary values (e.g., 20°N when latlim=(20, 50)) were being marked invisible.

Solution:
1. Set gridliner xlim/ylim explicitly before drawing (cartopy >= 0.19)
2. Force boundary labels to be visible if their positions are within the
   axes extent, both in get_tightbbox() and draw() methods
3. Added _force_boundary_label_visibility() helper method

This fixes the test_boundary_labels_negative_longitude test which was failing
since it was added in commit d3f8342.

* Revert "Fix boundary label visibility issue in cartopy"

This reverts commit 794e7a5.

* Fix test_boundary_labels tests to match actual cartopy behavior

The test helper was checking total label count instead of visible labels,
and the negative longitude test expected a boundary label (20°N) to be
visible when cartopy actually hides it due to floating point precision.

Changes:
- Modified _check_boundary_labels() to check visible label count, not total
- Updated test_boundary_labels_negative_longitude to expect only the labels
  that are actually visible (35°N, 50°N) instead of all 3

This test was failing since it was first added in d3f8342.

* Remove _adjust_panel_positions call from GeoAxes.draw()

The method is only defined in _CartopyAxes, not _BasemapAxes, so calling
it from the base GeoAxes.draw() causes AttributeError for basemap axes.

The adjustment is only needed for cartopy's apply_aspect() behavior, so
it should only be called in _CartopyAxes.get_tightbbox() where it belongs.

* Override draw() in _CartopyAxes to adjust panel positions

Instead of calling _adjust_panel_positions() from base GeoAxes.draw()
(which breaks basemap), override draw() specifically in _CartopyAxes.
This ensures panel alignment works for cartopy while keeping basemap
compatibility.

* make subplots_adjust work with both backend

* Revert "make subplots_adjust work with both backend"

This reverts commit 800f983.

* this works but generates different sizes

* fix failing tests

* this fails locally but should pass on GHA

* Fix unequal slicing for Gridspec (#435)

* fix remaining issues

* dedup logic

* Dedup geo panel alignment logic
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.

Bug: IndexError (shape mismatch) when using 2D slicing on SubplotGrid

2 participants