Skip to content

Commit 1716f85

Browse files
committed
Improve minor tick toggling, misc cleanup
1 parent 6925276 commit 1716f85

1 file changed

Lines changed: 88 additions & 43 deletions

File tree

proplot/axes.py

Lines changed: 88 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,10 +1465,13 @@ def parametric(self, *args, values=None,
14651465
# Create LineCollection and update with values
14661466
hs = mcollections.LineCollection(
14671467
np.array(coords), cmap=cmap, norm=norm,
1468-
linestyles='-', capstyle='butt', joinstyle='miter')
1468+
linestyles='-', capstyle='butt', joinstyle='miter'
1469+
)
14691470
hs.set_array(np.array(values))
1470-
hs.update({key: value for key, value in kwargs.items()
1471-
if key not in ('color',)})
1471+
hs.update({
1472+
key: value for key, value in kwargs.items()
1473+
if key not in ('color',)
1474+
})
14721475

14731476
# Add collection, with some custom attributes
14741477
self.add_collection(hs)
@@ -1937,7 +1940,8 @@ def format(
19371940
Parameters
19381941
----------
19391942
aspect : {'auto', 'equal'}, optional
1940-
The aspect ratio mode.
1943+
The aspect ratio mode. See `~matplotlib.axes.Axes.set_aspect`
1944+
for details.
19411945
xlabel, ylabel : str, optional
19421946
The *x* and *y* axis labels. Applied with
19431947
`~matplotlib.axes.Axes.set_xlabel`
@@ -2089,25 +2093,39 @@ def format(
20892093
yformatter_kw = yformatter_kw or {}
20902094
xminorlocator_kw = xminorlocator_kw or {}
20912095
yminorlocator_kw = yminorlocator_kw or {}
2096+
20922097
# Flexible keyword args, declare defaults
20932098
xmargin = _notNone(xmargin, rc['axes.xmargin'])
20942099
ymargin = _notNone(ymargin, rc['axes.ymargin'])
20952100
xtickdir = _notNone(xtickdir, rc['xtick.direction'])
20962101
ytickdir = _notNone(ytickdir, rc['ytick.direction'])
20972102
xtickminor = _notNone(xtickminor, rc['xtick.minor.visible'])
20982103
ytickminor = _notNone(ytickminor, rc['ytick.minor.visible'])
2099-
xformatter = _notNone(xticklabels, xformatter,
2100-
None, names=('xticklabels', 'xformatter'))
2101-
yformatter = _notNone(yticklabels, yformatter,
2102-
None, names=('yticklabels', 'yformatter'))
2103-
xlocator = _notNone(xticks, xlocator, None,
2104-
names=('xticks', 'xlocator'))
2105-
ylocator = _notNone(yticks, ylocator, None,
2106-
names=('yticks', 'ylocator'))
2107-
xminorlocator = _notNone(xminorticks, xminorlocator, None, names=(
2108-
'xminorticks', 'xminorlocator'))
2109-
yminorlocator = _notNone(yminorticks, yminorlocator, None, names=(
2110-
'yminorticks', 'yminorlocator'))
2104+
xformatter = _notNone(
2105+
xticklabels, xformatter, None,
2106+
names=('xticklabels', 'xformatter')
2107+
)
2108+
yformatter = _notNone(
2109+
yticklabels, yformatter, None,
2110+
names=('yticklabels', 'yformatter')
2111+
)
2112+
xlocator = _notNone(
2113+
xticks, xlocator, None,
2114+
names=('xticks', 'xlocator')
2115+
)
2116+
ylocator = _notNone(
2117+
yticks, ylocator, None,
2118+
names=('yticks', 'ylocator')
2119+
)
2120+
xminorlocator = _notNone(
2121+
xminorticks, xminorlocator, None,
2122+
names=('xminorticks', 'xminorlocator')
2123+
)
2124+
yminorlocator = _notNone(
2125+
yminorticks, yminorlocator, None,
2126+
names=('yminorticks', 'yminorlocator')
2127+
)
2128+
21112129
# Grid defaults are more complicated
21122130
axis = rc.get('axes.grid.axis') # always need this property
21132131
grid, which = rc['axes.grid'], rc['axes.grid.which']
@@ -2116,18 +2134,22 @@ def format(
21162134
grid = rc.get('axes.grid')
21172135
elif which is None:
21182136
which = rc.get('axes.grid.which')
2119-
xgrid = _notNone(xgrid,
2120-
grid and axis in ('x', 'both')
2121-
and which in ('major', 'both'))
2122-
ygrid = _notNone(ygrid,
2123-
grid and axis in ('y', 'both')
2124-
and which in ('major', 'both'))
2125-
xgridminor = _notNone(xgridminor, grid
2126-
and axis in ('x', 'both')
2127-
and which in ('minor', 'both'))
2128-
ygridminor = _notNone(ygridminor, grid
2129-
and axis in ('y', 'both')
2130-
and which in ('minor', 'both'))
2137+
xgrid = _notNone(
2138+
xgrid, grid and axis in ('x', 'both')
2139+
and which in ('major', 'both')
2140+
)
2141+
ygrid = _notNone(
2142+
ygrid, grid and axis in ('y', 'both')
2143+
and which in ('major', 'both')
2144+
)
2145+
xgridminor = _notNone(
2146+
xgridminor, grid and axis in ('x', 'both')
2147+
and which in ('minor', 'both')
2148+
)
2149+
ygridminor = _notNone(
2150+
ygridminor, grid and axis in ('y', 'both')
2151+
and which in ('minor', 'both')
2152+
)
21312153

21322154
# Sensible defaults for spine, tick, tick label, and label locs
21332155
# NOTE: Allow tick labels to be present without ticks! User may
@@ -2169,7 +2191,7 @@ def format(
21692191
tickloc, spineloc,
21702192
ticklabelloc, labelloc,
21712193
grid, gridminor,
2172-
tickminor, tickminorlocator,
2194+
tickminor, minorlocator,
21732195
lim, reverse, scale,
21742196
locator, tickrange,
21752197
formatter, tickdir,
@@ -2418,27 +2440,48 @@ def grid_dict(grid):
24182440
self._update_axislabels(x, **kw)
24192441

24202442
# Major and minor locator
2421-
# WARNING: MultipleLocator fails sometimes, notably when doing
2422-
# boxplot. Tick labels moved to left and are incorrect.
2443+
# NOTE: Parts of API (dualxy) rely on minor tick toggling
2444+
# preserving the isDefault_minloc setting. In future should
2445+
# override the default matplotlib API minorticks_on!
2446+
# NOTE: Unlike matplotlib API when "turning on" minor ticks
2447+
# we *always* use the scale default, thanks to scale classes
2448+
# refactoring with _ScaleBase. See Axes.minorticks_on.
24232449
if locator is not None:
24242450
locator = axistools.Locator(locator, **locator_kw)
24252451
axis.set_major_locator(locator)
24262452
if isinstance(locator, mticker.IndexLocator):
24272453
tickminor = False # 'index' minor ticks make no sense
2428-
if not tickminor and tickminorlocator is None:
2454+
if tickminor or minorlocator:
2455+
isdefault = minorlocator is None
2456+
if isdefault:
2457+
minorlocator = getattr(
2458+
axis._scale, '_default_minor_locator', None
2459+
)
2460+
if not minorlocator:
2461+
minorlocator = axistools.Locator('minor')
2462+
else:
2463+
minorlocator = axistools.Locator(
2464+
minorlocator, **minorlocator_kw
2465+
)
2466+
axis.set_minor_locator(minorlocator)
2467+
axis.isDefault_minloc = isdefault
2468+
elif tickminor is not None and not tickminor:
2469+
# NOTE: Generally if you *enable* minor ticks on a dual
2470+
# axis, want to allow FuncScale updates to change the
2471+
# minor tick locators. If you *disable* minor ticks, do
2472+
# not want FuncScale applications to turn them on. So we
2473+
# allow below to set isDefault_minloc to False.
24292474
axis.set_minor_locator(axistools.Locator('null'))
2430-
elif tickminorlocator is not None:
2431-
axis.set_minor_locator(axistools.Locator(
2432-
tickminorlocator, **minorlocator_kw))
24332475

24342476
# Major formatter
2435-
# NOTE: Only reliable way to disable ticks labels and then
2436-
# restore them is by messing with the formatter, *not* setting
2437-
# labelleft=False, labelright=False, etc.
2477+
# NOTE: The only reliable way to disable ticks labels and then
2478+
# restore them is by messing with the *formatter*, rather than
2479+
# setting labelleft=False, labelright=False, etc.
24382480
if (formatter is not None or tickrange is not None) and not (
2439-
isinstance(axis.get_major_formatter(),
2440-
mticker.NullFormatter)
2441-
and getattr(self, '_share' + x)):
2481+
isinstance(
2482+
axis.get_major_formatter(), mticker.NullFormatter
2483+
) and getattr(self, '_share' + x)
2484+
):
24422485
# Tick range
24432486
if tickrange is not None:
24442487
if formatter not in (None, 'auto'):
@@ -2463,10 +2506,12 @@ def grid_dict(grid):
24632506
# locators into fixed version.
24642507
# * Most locators take no arguments in __call__, and some do
24652508
# not have tick_values method, so we just call them.
2466-
if (bounds is not None
2509+
if (
2510+
bounds is not None
24672511
or fixticks
24682512
or isinstance(formatter, mticker.FixedFormatter)
2469-
or axis.get_scale() == 'cutoff'):
2513+
or axis.get_scale() == 'cutoff'
2514+
):
24702515
if bounds is None:
24712516
bounds = getattr(self, 'get_' + x + 'lim')()
24722517
locator = axistools.Locator([

0 commit comments

Comments
 (0)