8000 fix argument checks in axis/base.margins · matplotlib/matplotlib@3756aaf · GitHub
[go: up one dir, main page]

Skip to content < 65F7 script type="application/json" data-target="react-partial.embeddedData">{"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}

Commit 3756aaf

Browse files
fix argument checks in axis/base.margins
If keyword arguments where used, like mentioned in the documentation, the code would fail as if more than two parameters where given (since len(args) would be 0 -> != 1/2)
1 parent 7f7aa5e commit 3756aaf

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ def margins(self, *args, **kw):
18251825
mx = my = args[0]
18261826
elif len(args) == 2:
18271827
mx, my = args
1828-
else:
1828+
elif len(args) > 2:
18291829
raise ValueError("more than two arguments were supplied")
18301830
if mx is not None:
18311831
self.set_xmargin(mx)
Loading
Loading
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,25 @@ def test_pie_ccw_true():
31093109
# Set aspect ratio to be equal so that pie is drawn as a circle.
31103110
plt.axis('equal')
31113111

3112+
@image_comparison(baseline_images=['margins_1', 'margins_1_05_arg', 'margins_1_05_kwarg'], extensions=['png'])
3113+
def test_margins():
3114+
# test all
3115+
data = [1, 10]
3116+
3117+
fig1, ax1 = plt.subplots(1, 1)
3118+
ax1.plot(data)
3119+
ax1.margins(1)
3120+
assert_equal(ax1.margins(), (1, 1))
3121+
3122+
fig2, ax2 = plt.subplots(1, 1)
3123+
ax2.plot(data)
3124+
ax2.margins(1, 0.5)
3125+
assert_equal(ax2.margins(), (1, 0.5))
3126+
3127+
fig3, ax3 = plt.subplots(1, 1)
3128+
ax3.plot(data)
3129+
ax3.margins(x=1, y=0.5)
3130+
assert_equal(ax3.margins(), (1, 0.5))
31123131

31133132
@cleanup
31143133
def test_pathological_hexbin():

0 commit comments

Comments
 (0)
0