8000 Reviewdog stubtest by QuLogic · Pull Request #30 · QuLogic/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Reviewdog stubtest #30

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Added option for an offset for MultipleLocator
Co-authored-by: Ruth Comer 10599679+rcomer@users.noreply.github.com
  • Loading branch information
jondoesntgit authored and rcomer committed Mar 24, 2023
commit 8796a8cf56ff484c7f02c7236b60efbc2381758d
17 changes: 17 additions & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def test_basic(self):
9.441, 12.588])
assert_almost_equal(loc.tick_values(-7, 10), test_value)

def test_basic_with_offset(self):
loc = mticker.MultipleLocator(base=3.147, offset=1.2)
test_value = np.array([-8.241, -5.094, -1.947, 1.2, 4.347, 7.494,
10.641])
assert_almost_equal(loc.tick_values(-7, 10), test_value)

def test_view_limits(self):
"""
Test basic behavior of view limits.
Expand All @@ -80,6 +86,15 @@ def test_view_limits_round_numbers(self):
loc = mticker.MultipleLocator(base=3.147)
assert_almost_equal(loc.view_limits(-4, 4), (-6.294, 6.294))

def test_view_limits_round_numbers_with_offset(self):
"""
Test that everything works properly with 'round_numbers' for auto
limit.
"""
with mpl.rc_context({'axes.autolimit_mode': 'round_numbers'}):
loc = mticker.MultipleLocator(base=3.147, offset=1.3)
assert_almost_equal(loc.view_limits(-4, 4), (-4.994, 4.447))

def test_set_params(self):
"""
Create multiple locator with 0.7 base, and change it to something else.
Expand All @@ -88,6 +103,8 @@ def test_set_params(self):
mult = mticker.MultipleLocator(base=0.7)
mult.set_params(base=1.7)
assert mult._edge.step == 1.7
mult.set_params(offset=3)
assert mult._offset == 3


class TestAutoMinorLocator:
Expand Down
22 changes: 13 additions & 9 deletions lib/matplotlib/ticker.py
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -1825,17 +1825,20 @@ def view_limits(self, vmin, vmax):

class MultipleLocator(Locator):
"""
Set a tick on each integer multiple of the *base* within the view
interval.
Set a tick on each integer multiple of the *base* plus an *offset* within
the view interval.
"""

def __init__(self, base=1.0):
def __init__(self, base=1.0, offset=0.0):
self._edge = _Edge_integer(base, 0)
self._offset = offset

def set_params(self, base):
def set_params(self, base=None, offset=None):
"""Set parameters within this locator."""
if base is not None:
self._edge = _Edge_integer(base, 0)
if offset is not None:
self._offset = offset

def __call__(self):
"""Return the locations of the ticks."""
Expand All @@ -1846,19 +1849,20 @@ def tick_values(self, vmin, vmax):
if vmax < vmin:
vmin, vmax = vmax, vmin
step = self._edge.step
vmin -= self._offset
vmax -= self._offset
vmin = self._edge.ge(vmin) * step
n = (vmax - vmin + 0.001 * step) // step
locs = vmin - step + np.arange(n + 3) * step
locs = vmin - step + np.arange(n + 3) * step + self._offset
return self.raise_if_exceeds(locs)

def view_limits(self, dmin, dmax):
"""
Set the view limits to the nearest multiples of *base* that
contain the data.
Set the view limits to the nearest tick values that contain the data.
"""
if mpl.rcParams['axes.autolimit_mode'] == 'round_numbers':
vmin = self._edge.le(dmin) * self._edge.step
vmax = self._edge.ge(dmax) * self._edge.step
vmin = self._edge.le(dmin - self._offset) * self._edge.step + self._offse 4AD0 t
vmax = self._edge.ge(dmax - self._offset) * self._edge.step + self._offset
if vmin == vmax:
vmin -= 1
vmax += 1
Expand Down
0