Skip to content

Commit

Permalink
Add support for minor ticks in 3d axes.
Browse files Browse the repository at this point in the history
The actual implementation is shorter than deleting the copies of "Minor
ticks are not supported" in the various docstrings...
  • Loading branch information
anntzer committed Aug 7, 2019
1 parent cee82fb commit 6cd0ff6
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 48 deletions.
2 changes: 2 additions & 0 deletions doc/users/next_whats_new/2019-06-25-AL.rst
@@ -0,0 +1,2 @@
3D axes now support minor ticks
```````````````````````````````
1 change: 1 addition & 0 deletions lib/matplotlib/axis.py
Expand Up @@ -98,6 +98,7 @@ def __init__(self, axes, loc, label,
name = self.__name__.lower()

self._loc = loc
self._major = major

if size is None:
if major:
Expand Down
16 changes: 0 additions & 16 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Expand Up @@ -846,9 +846,6 @@ def set_zticks(self, *args, **kwargs):
Set z-axis tick locations.
See :meth:`matplotlib.axes.Axes.set_yticks` for more details.
.. note::
Minor ticks are not supported.
.. versionadded:: 1.1.0
"""
return self.zaxis.set_ticks(*args, **kwargs)
Expand All @@ -858,9 +855,6 @@ def get_zticks(self, minor=False):
Return the z ticks as a list of locations
See :meth:`matplotlib.axes.Axes.get_yticks` for more details.
.. note::
Minor ticks are not supported.
.. versionadded:: 1.1.0
"""
return self.zaxis.get_ticklocs(minor=minor)
Expand All @@ -877,10 +871,6 @@ def get_zminorticklabels(self):
"""
Get the ztick labels as a list of Text instances
.. note::
Minor ticks are not supported. This function was added
only for completeness.
.. versionadded :: 1.1.0
"""
return self.zaxis.get_minorticklabels()
Expand All @@ -890,9 +880,6 @@ def set_zticklabels(self, *args, **kwargs):
Set z-axis tick labels.
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
.. note::
Minor ticks are not supported by Axes3D objects.
.. versionadded:: 1.1.0
"""
return self.zaxis.set_ticklabels(*args, **kwargs)
Expand All @@ -902,9 +889,6 @@ def get_zticklabels(self, minor=False):
Get ztick labels as a list of Text instances.
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
.. note::
Minor ticks are not supported.
.. versionadded:: 1.1.0
"""
return self.zaxis.get_ticklabels(minor=minor)
Expand Down
86 changes: 54 additions & 32 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Expand Up @@ -73,33 +73,48 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args,
# Do not depend on this existing in future releases!
self._axinfo = self._AXINFO[adir].copy()
if rcParams['_internal.classic_mode']:
self._axinfo.update(
{'label': {'va': 'center',
'ha': 'center'},
'tick': {'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': rcParams['lines.linewidth']},
'axisline': {'linewidth': 0.75,
'color': (0, 0, 0, 1)},
'grid': {'color': (0.9, 0.9, 0.9, 1),
'linewidth': 1.0,
'linestyle': '-'},
})
self._axinfo.update({
'label': {'va': 'center', 'ha': 'center'},
'tick': {
'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': {
True: rcParams['lines.linewidth'], # major
False: rcParams['lines.linewidth'], # minor
}
},
'axisline': {'linewidth': 0.75, 'color': (0, 0, 0, 1)},
'grid': {
'color': (0.9, 0.9, 0.9, 1),
'linewidth': 1.0,
'linestyle': '-',
},
})
else:
self._axinfo.update(
{'label': {'va': 'center',
'ha': 'center'},
'tick': {'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': rcParams.get(
adir + 'tick.major.width',
rcParams['xtick.major.width'])},
'axisline': {'linewidth': rcParams['axes.linewidth'],
'color': rcParams['axes.edgecolor']},
'grid': {'color': rcParams['grid.color'],
'linewidth': rcParams['grid.linewidth'],
'linestyle': rcParams['grid.linestyle']},
})
self._axinfo.update({
'label': {'va': 'center', 'ha': 'center'},
'tick': {
'inward_factor': 0.2,
'outward_factor': 0.1,
'linewidth': {
True: ( # major
rcParams['xtick.major.width'] if adir in 'xz' else
rcParams['ytick.major.width']),
False: ( # minor
rcParams['xtick.minor.width'] if adir in 'xz' else
rcParams['ytick.minor.width']),
}
},
'axisline': {
'linewidth': rcParams['axes.linewidth'],
'color': rcParams['axes.edgecolor'],
},
'grid': {
'color': rcParams['grid.color'],
'linewidth': rcParams['grid.linewidth'],
'linestyle': rcParams['grid.linestyle'],
},
})

maxis.XAxis.__init__(self, axes, *args, **kwargs)

Expand Down Expand Up @@ -140,11 +155,17 @@ def get_tick_positions(self):
def get_major_ticks(self, numticks=None):
ticks = maxis.XAxis.get_major_ticks(self, numticks)
for t in ticks:
t.tick1line.set_transform(self.axes.transData)
t.tick2line.set_transform(self.axes.transData)
t.gridline.set_transform(self.axes.transData)
t.label1.set_transform(self.axes.transData)
t.label2.set_transform(self.axes.transData)
for obj in [
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
obj.set_transform(self.axes.transData)
return ticks

def get_minor_ticks(self, numticks=None):
ticks = maxis.XAxis.get_minor_ticks(self, numticks)
for t in ticks:
for obj in [
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
obj.set_transform(self.axes.transData)
return ticks

def set_pane_pos(self, xys):
Expand Down Expand Up @@ -403,7 +424,8 @@ def draw(self, renderer):
renderer.M)

tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly))
tick.tick1line.set_linewidth(info['tick']['linewidth'])
tick.tick1line.set_linewidth(
info['tick']['linewidth'][tick._major])
tick.draw(renderer)

renderer.close_group('axis3d')
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Expand Up @@ -942,3 +942,14 @@ def get_formatters(ax, names):
for fmt in get_formatters(row[4], names):
fmt.set_useMathText(
not mpl.rcParams["axes.formatter.use_mathtext"])


@image_comparison(["minor_ticks.png"], style="default")
def test_minor_ticks():
ax = plt.figure().add_subplot(projection="3d")
ax.set_xticks([0.25], minor=True)
ax.set_xticklabels(["quarter"], minor=True)
ax.set_yticks([0.33], minor=True)
ax.set_yticklabels(["third"], minor=True)
ax.set_zticks([0.50], minor=True)
ax.set_zticklabels(["half"], minor=True)

0 comments on commit 6cd0ff6

Please sign in to comment.