8000 BUG: fix autoscale_view with log scale and margins · matplotlib/matplotlib@2edf1e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2edf1e3

Browse files
committed
BUG: fix autoscale_view with log scale and margins
LogLocator.view_limits was always clipping vmin to minpos; now it sets vmin to minpos only if vmin <= 0.
1 parent dc13688 commit 2edf1e3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,6 +4667,21 @@ def test_fillbetween_cycle():
46674667
assert tuple(cc.get_edgecolors().squeeze()) == tuple(edge_target)
46684668

46694669

4670+
@cleanup
4671+
def test_log_margins():
4672+
plt.rcParams['axes.autolimit_mode'] = 'data'
4673+
fig, ax = plt.subplots()
4674+
margin = 0.05
4675+
ax.set_xmargin(margin)
4676+
ax.semilogx([1, 10], [1, 10])
4677+
xlim0, xlim1 = ax.get_xlim()
4678+
transform = ax.xaxis.get_transform()
4679+
xlim0t, xlim1t = transform.transform([xlim0, xlim1])
4680+
x0t, x1t = transform.transform([1, 10])
4681+
delta = (x1t - x0t) * margin
4682+
assert_allclose([xlim0t + delta, xlim1t - delta], [x0t, x1t])
4683+
4684+
46704685
if __name__ == '__main__':
46714686
import nose
46724687
import sys

lib/matplotlib/ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ def view_limits(self, vmin, vmax):
19121912
"Data has no positive values, and therefore can not be "
19131913
"log-scaled.")
19141914

1915-
if vmin <= minpos:
1915+
if vmin <= 0:
19161916
vmin = minpos
19171917

19181918
if rcParams['axes.autolimit_mode'] == 'round_numbers':

0 commit comments

Comments
 (0)
0