Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[fix] Spine.set_bounds() does not take parameter **None** as expected#30330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
leakyH wants to merge6 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromleakyH:fixSpineBounds
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletionslib/matplotlib/spines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -238,14 +238,7 @@ def _adjust_location(self):
if self.spine_type == 'circle':
return

if self._bounds is not None:
low, high = self._bounds
elif self.spine_type in ('left', 'right'):
low, high = self.axes.viewLim.intervaly
elif self.spine_type in ('top', 'bottom'):
low, high = self.axes.viewLim.intervalx
else:
raise ValueError(f'unknown spine spine_type: {self.spine_type}')
low, high = self.get_bounds()

if self._patch_type == 'arc':
if self.spine_type in ('bottom', 'top'):
Expand DownExpand Up@@ -424,7 +417,7 @@ def set_bounds(self, low=None, high=None):
'set_bounds() method incompatible with circular spines')
if high is None and np.iterable(low):
low, high = low
old_low, old_high = self.get_bounds() or (None, None)
old_low, old_high = self.get_bounds()
if low is None:
low = old_low
if high is None:
Expand All@@ -433,8 +426,15 @@ def set_bounds(self, low=None, high=None):
self.stale = True

def get_bounds(self):
"""Get the bounds of the spine."""
return self._bounds
"""Get the bounds of the spine. Take None into consideration."""
if self._bounds is not None:
return self._bounds
elif self.spine_type in ('left', 'right'):
return self.axes.viewLim.intervaly
elif self.spine_type in ('top', 'bottom'):
return self.axes.viewLim.intervalx
else:
raise ValueError(f'unknown spine spine_type: {self.spine_type}')

@classmethod
def linear_spine(cls, axes, spine_type, **kwargs):
Expand Down
29 changes: 29 additions & 0 deletionslib/matplotlib/tests/test_spines.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -166,3 +166,32 @@ def test_arc_spine_inner_no_axis():
assert ax.spines["inner"].axis is None

fig.draw_without_rendering()


def test_spine_set_bounds_with_none():
"""Test that set_bounds(None, ...) uses original axis view limits."""
fig, ax = plt.subplots()

# Plot some data to set axis limits
x = np.linspace(0, 10, 100)
y = np.sin(x)
ax.plot(x, y)

xlim = ax.viewLim.intervalx
ylim = ax.viewLim.intervaly
# Use modified set_bounds with None
ax.spines['bottom'].set_bounds(0, None)
ax.spines['left'].set_bounds(None, None)

# Check that get_bounds returns correct numeric values
bottom_bound = ax.spines['bottom'].get_bounds()
left_bound = ax.spines['left'].get_bounds()
left_bounds_not_None = (left_bound[0] is not None) and (left_bound[1] is not None)

assert bottom_bound[1] is not None, "Higher bound should be numeric"
assert left_bounds_not_None, "left bound should be numeric"
assert np.isclose(bottom_bound[0], 0), "Lower bound should match provided value"
assert np.isclose(bottom_bound[1],
xlim[1]), "Upper bound should match original value"
assert np.isclose(left_bound[0], ylim[0]), "Lower bound should match original value"
assert np.isclose(left_bound[1], ylim[1]), "Upper bound should match original value"
Loading

[8]ページ先頭

©2009-2025 Movatter.jp