Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5458309

Browse files
author
MKhadra
committed
Unit tests added to test_ticker.py
1 parent 2e0e6f4 commit 5458309

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,70 @@ def test_additional(self, lim, ref):
194194

195195
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), ref)
196196

197+
def test_ndivs_rcParams_auto(self):
198+
# when no parameter is given rcParams should be used
199+
# auto
200+
mpl.rc_context(rc={'xtick.minor.ndivs': 'auto'})
201+
mpl.rc_context(rc={'ytick.minor.ndivs': 'auto'})
202+
fig, ax = plt.subplots()
203+
ax.set_xlim(0, 1.39)
204+
ax.set_ylim(0, 1.39)
205+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
206+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
207+
208+
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
209+
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
210+
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
211+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
212+
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), test_value)
213+
214+
def test_ndivs_rcParams_int(self):
215+
# when no parameter is given rcParams should be used
216+
# non-neg int
217+
mpl.rc_context(rc={'xtick.minor.ndivs': 2})
218+
mpl.rc_context(rc={'ytick.minor.ndivs': 2})
219+
fig, ax = plt.subplots()
220+
ax.set_xlim(0, 4)
221+
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
222+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator())
223+
224+
ax.set_ylim(0, 4)
225+
ax.yaxis.set_major_locator(mticker.MultipleLocator(1))
226+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator())
227+
228+
test_value = np.array([0.5, 1.5, 2.5, 3.5])
229+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
230+
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), test_value)
231+
232+
def test_ndivs_auto(self):
233+
# when auto is given set ndivs to either 4 or 5
234+
fig, ax = plt.subplots()
235+
ax.set_xlim(0, 1.39)
236+
ax.set_ylim(0, 1.39)
237+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator('auto'))
238+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator('auto'))
239+
240+
test_value = np.array([0.05, 0.1, 0.15, 0.25, 0.3, 0.35, 0.45,
241+
0.5, 0.55, 0.65, 0.7, 0.75, 0.85, 0.9,
242+
0.95, 1.05, 1.1, 1.15, 1.25, 1.3, 1.35])
243+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
244+
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), test_value)
245+
246+
def test_ndivs_int(self):
247+
# when an integer is given, use that integer
248+
fig, ax = plt.subplots()
249+
ax.set_xlim(0, 4)
250+
ax.xaxis.set_major_locator(mticker.MultipleLocator(1))
251+
ax.xaxis.set_minor_locator(mticker.AutoMinorLocator(2))
252+
253+
ax.set_ylim(0, 4)
254+
ax.yaxis.set_major_locator(mticker.MultipleLocator(1))
255+
ax.yaxis.set_minor_locator(mticker.AutoMinorLocator(2))
256+
257+
test_value = np.array([0.5, 1.5, 2.5, 3.5])
258+
assert_almost_equal(ax.xaxis.get_ticklocs(minor=True), test_value)
259+
assert_almost_equal(ax.yaxis.get_ticklocs(minor=True), test_value)
260+
197261

198262
class TestLogLocator:
199263
def test_basic(self):

0 commit comments

Comments
 (0)