Skip to content

Commit 8e09a9e

Browse files
committed
Add support for minor ticks in 3d axes.
The actual implementation is shorter than deleting the copies of "Minor ticks are not supported" in the various docstrings...
1 parent 1a924b1 commit 8e09a9e

File tree

6 files changed

+68
-48
lines changed

6 files changed

+68
-48
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3D axes now support minor ticks
2+
```````````````````````````````

lib/matplotlib/axis.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self, axes, loc, label=None,
9999
name = self.__name__.lower()
100100

101101
self._loc = loc
102+
self._major = major
102103

103104
major_minor = "major" if major else "minor"
104105

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,6 @@ def set_zticks(self, *args, **kwargs):
822822
Set z-axis tick locations.
823823
See :meth:`matplotlib.axes.Axes.set_yticks` for more details.
824824
825-
.. note::
826-
Minor ticks are not supported.
827-
828825
.. versionadded:: 1.1.0
829826
"""
830827
return self.zaxis.set_ticks(*args, **kwargs)
@@ -835,9 +832,6 @@ def get_zticks(self, minor=False):
835832
Return the z ticks as a list of locations
836833
See :meth:`matplotlib.axes.Axes.get_yticks` for more details.
837834
838-
.. note::
839-
Minor ticks are not supported.
840-
841835
.. versionadded:: 1.1.0
842836
"""
843837
return self.zaxis.get_ticklocs(minor=minor)
@@ -854,10 +848,6 @@ def get_zminorticklabels(self):
854848
"""
855849
Get the ztick labels as a list of Text instances
856850
857-
.. note::
858-
Minor ticks are not supported. This function was added
859-
only for completeness.
860-
861851
.. versionadded:: 1.1.0
862852
"""
863853
return self.zaxis.get_minorticklabels()
@@ -867,9 +857,6 @@ def set_zticklabels(self, *args, **kwargs):
867857
Set z-axis tick labels.
868858
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
869859
870-
.. note::
871-
Minor ticks are not supported by Axes3D objects.
872-
873860
.. versionadded:: 1.1.0
874861
"""
875862
return self.zaxis.set_ticklabels(*args, **kwargs)
@@ -879,9 +866,6 @@ def get_zticklabels(self, minor=False):
879866
Get ztick labels as a list of Text instances.
880867
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
881868
882-
.. note::
883-
Minor ticks are not supported.
884-
885869
.. versionadded:: 1.1.0
886870
"""
887871
return self.zaxis.get_ticklabels(minor=minor)

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,48 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args,
5959
# Do not depend on this existing in future releases!
6060
self._axinfo = self._AXINFO[adir].copy()
6161
if rcParams['_internal.classic_mode']:
62-
self._axinfo.update(
63-
{'label': {'va': 'center',
64-
'ha': 'center'},
65-
'tick': {'inward_factor': 0.2,
66-
'outward_factor': 0.1,
67-
'linewidth': rcParams['lines.linewidth']},
68-
'axisline': {'linewidth': 0.75,
69-
'color': (0, 0, 0, 1)},
70-
'grid': {'color': (0.9, 0.9, 0.9, 1),
71-
'linewidth': 1.0,
72-
'linestyle': '-'},
73-
})
62+
self._axinfo.update({
63+
'label': {'va': 'center', 'ha': 'center'},
64+
'tick': {
65+
'inward_factor': 0.2,
66+
'outward_factor': 0.1,
67+
'linewidth': {
68+
True: rcParams['lines.linewidth'], # major
69+
False: rcParams['lines.linewidth'], # minor
70+
}
71+
},
72+
'axisline': {'linewidth': 0.75, 'color': (0, 0, 0, 1)},
73+
'grid': {
74+
'color': (0.9, 0.9, 0.9, 1),
75+
'linewidth': 1.0,
76+
'linestyle': '-',
77+
},
78+
})
7479
else:
75-
self._axinfo.update(
76-
{'label': {'va': 'center',
77-
'ha': 'center'},
78-
'tick': {'inward_factor': 0.2,
79-
'outward_factor': 0.1,
80-
'linewidth': rcParams.get(
81-
adir + 'tick.major.width',
82-
rcParams['xtick.major.width'])},
83-
'axisline': {'linewidth': rcParams['axes.linewidth'],
84-
'color': rcParams['axes.edgecolor']},
85-
'grid': {'color': rcParams['grid.color'],
86-
'linewidth': rcParams['grid.linewidth'],
87-
'linestyle': rcParams['grid.linestyle']},
88-
})
80+
self._axinfo.update({
81+
'label': {'va': 'center', 'ha': 'center'},
82+
'tick': {
83+
'inward_factor': 0.2,
84+
'outward_factor': 0.1,
85+
'linewidth': {
86+
True: ( # major
87+
rcParams['xtick.major.width'] if adir in 'xz' else
88+
rcParams['ytick.major.width']),
89+
False: ( # minor
90+
rcParams['xtick.minor.width'] if adir in 'xz' else
91+
rcParams['ytick.minor.width']),
92+
}
93+
},
94+
'axisline': {
95+
'linewidth': rcParams['axes.linewidth'],
96+
'color': rcParams['axes.edgecolor'],
97+
},
98+
'grid': {
99+
'color': rcParams['grid.color'],
100+
'linewidth': rcParams['grid.linewidth'],
101+
'linestyle': rcParams['grid.linestyle'],
102+
},
103+
})
89104

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

@@ -120,11 +135,17 @@ def init3d(self):
120135
def get_major_ticks(self, numticks=None):
121136
ticks = maxis.XAxis.get_major_ticks(self, numticks)
122137
for t in ticks:
123-
t.tick1line.set_transform(self.axes.transData)
124-
t.tick2line.set_transform(self.axes.transData)
125-
t.gridline.set_transform(self.axes.transData)
126-
t.label1.set_transform(self.axes.transData)
127-
t.label2.set_transform(self.axes.transData)
138+
for obj in [
139+
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
140+
obj.set_transform(self.axes.transData)
141+
return ticks
142+
143+
def get_minor_ticks(self, numticks=None):
144+
ticks = maxis.XAxis.get_minor_ticks(self, numticks)
145+
for t in ticks:
146+
for obj in [
147+
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
148+
obj.set_transform(self.axes.transData)
128149
return ticks
129150

130151
def set_pane_pos(self, xys):
@@ -370,7 +391,8 @@ def draw(self, renderer):
370391
lx, ly, lz = proj3d.proj_transform(*pos, renderer.M)
371392

372393
tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly))
373-
tick.tick1line.set_linewidth(info['tick']['linewidth'])
394+
tick.tick1line.set_linewidth(
395+
info['tick']['linewidth'][tick._major])
374396
tick.draw(renderer)
375397

376398
renderer.close_group('axis3d')
Loading

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,3 +905,14 @@ def test_quiver3D_smoke(fig_test, fig_ref):
905905
for fig, length in zip((fig_ref, fig_test), (1, 1.0)):
906906
ax = fig.gca(projection="3d")
907907
ax.quiver(x, y, z, u, v, w, length=length, pivot=pivot)
908+
909+
910+
@image_comparison(["minor_ticks.png"], style="mpl20")
911+
def test_minor_ticks():
912+
ax = plt.figure().add_subplot(projection="3d")
913+
ax.set_xticks([0.25], minor=True)
914+
ax.set_xticklabels(["quarter"], minor=True)
915+
ax.set_yticks([0.33], minor=True)
916+
ax.set_yticklabels(["third"], minor=True)
917+
ax.set_zticks([0.50], minor=True)
918+
ax.set_zticklabels(["half"], minor=True)

0 commit comments

Comments
 (0)