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 Jun 25, 2019
1 parent e8b40f9 commit 8f9fdff
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 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
```````````````````````````````
16 changes: 0 additions & 16 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Expand Up @@ -862,9 +862,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 @@ -874,9 +871,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 @@ -894,10 +888,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 cbook.silent_list('Text zticklabel',
Expand All @@ -908,9 +898,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 @@ -920,9 +907,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 cbook.silent_list('Text zticklabel',
Expand Down
16 changes: 11 additions & 5 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Expand Up @@ -140,11 +140,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
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 @@ -903,3 +903,14 @@ def test_ax3d_tickcolour():
assert tick.tick1line._color == 'red'
for tick in ax.zaxis.get_major_ticks():
assert tick.tick1line._color == 'red'


@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 8f9fdff

Please sign in to comment.