Skip to content

Commit

Permalink
Merge pull request #14626 from anntzer/3dminor
Browse files Browse the repository at this point in the history
Add support for minor ticks in 3d axes.
  • Loading branch information
QuLogic committed Mar 24, 2020
2 parents 1a924b1 + 8e09a9e commit ee15e90
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 @@ -99,6 +99,7 @@ def __init__(self, axes, loc, label=None,
name = self.__name__.lower()

self._loc = loc
self._major = major

major_minor = "major" if major else "minor"

Expand Down
16 changes: 0 additions & 16 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Expand Up @@ -822,9 +822,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 @@ -835,9 +832,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 @@ -854,10 +848,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 @@ -867,9 +857,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 @@ -879,9 +866,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 @@ -59,33 +59,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 @@ -120,11 +135,17 @@ def init3d(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 @@ -370,7 +391,8 @@ def draw(self, renderer):
lx, ly, lz = proj3d.proj_transform(*pos, 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 @@ -905,3 +905,14 @@ def test_quiver3D_smoke(fig_test, fig_ref):
for fig, length in zip((fig_ref, fig_test), (1, 1.0)):
ax = fig.gca(projection="3d")
ax.quiver(x, y, z, u, v, w, length=length, pivot=pivot)


@image_comparison(["minor_ticks.png"], style="mpl20")
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 ee15e90

Please sign in to comment.