Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cbe0a4

Browse filesBrowse 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 6870ac0 commit 7cbe0a4
Copy full SHA for 7cbe0a4

File tree

Expand file treeCollapse file tree

6 files changed

+68
-48
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+68
-48
lines changed
+2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def __init__(self, axes, loc, label,
9898
name = self.__name__.lower()
9999

100100
self._loc = loc
101+
self._major = major
101102

102103
if size is None:
103104
if major:

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
-16Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -848,9 +848,6 @@ def set_zticks(self, *args, **kwargs):
848848
Set z-axis tick locations.
849849
See :meth:`matplotlib.axes.Axes.set_yticks` for more details.
850850
851-
.. note::
852-
Minor ticks are not supported.
853-
854851
.. versionadded:: 1.1.0
855852
"""
856853
return self.zaxis.set_ticks(*args, **kwargs)
@@ -861,9 +858,6 @@ def get_zticks(self, minor=False):
861858
Return the z ticks as a list of locations
862859
See :meth:`matplotlib.axes.Axes.get_yticks` for more details.
863860
864-
.. note::
865-
Minor ticks are not supported.
866-
867861
.. versionadded:: 1.1.0
868862
"""
869863
return self.zaxis.get_ticklocs(minor=minor)
@@ -880,10 +874,6 @@ def get_zminorticklabels(self):
880874
"""
881875
Get the ztick labels as a list of Text instances
882876
883-
.. note::
884-
Minor ticks are not supported. This function was added
885-
only for completeness.
886-
887877
.. versionadded :: 1.1.0
888878
"""
889879
return self.zaxis.get_minorticklabels()
@@ -893,9 +883,6 @@ def set_zticklabels(self, *args, **kwargs):
893883
Set z-axis tick labels.
894884
See :meth:`matplotlib.axes.Axes.set_yticklabels` for more details.
895885
896-
.. note::
897-
Minor ticks are not supported by Axes3D objects.
898-
899886
.. versionadded:: 1.1.0
900887
"""
901888
return self.zaxis.set_ticklabels(*args, **kwargs)
@@ -905,9 +892,6 @@ def get_zticklabels(self, minor=False):
905892
Get ztick labels as a list of Text instances.
906893
See :meth:`matplotlib.axes.Axes.get_yticklabels` for more details.
907894
908-
.. note::
909-
Minor ticks are not supported.
910-
911895
.. versionadded:: 1.1.0
912896
"""
913897
return self.zaxis.get_ticklabels(minor=minor)

‎lib/mpl_toolkits/mplot3d/axis3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axis3d.py
+54-32Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,33 +68,48 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args,
6868
# Do not depend on this existing in future releases!
6969
self._axinfo = self._AXINFO[adir].copy()
7070
if rcParams['_internal.classic_mode']:
71-
self._axinfo.update(
72-
{'label': {'va': 'center',
73-
'ha': 'center'},
74-
'tick': {'inward_factor': 0.2,
75-
'outward_factor': 0.1,
76-
'linewidth': rcParams['lines.linewidth']},
77-
'axisline': {'linewidth': 0.75,
78-
'color': (0, 0, 0, 1)},
79-
'grid': {'color': (0.9, 0.9, 0.9, 1),
80-
'linewidth': 1.0,
81-
'linestyle': '-'},
82-
})
71+
self._axinfo.update({
72+
'label': {'va': 'center', 'ha': 'center'},
73+
'tick': {
74+
'inward_factor': 0.2,
75+
'outward_factor': 0.1,
76+
'linewidth': {
77+
True: rcParams['lines.linewidth'], # major
78+
False: rcParams['lines.linewidth'], # minor
79+
}
80+
},
81+
'axisline': {'linewidth': 0.75, 'color': (0, 0, 0, 1)},
82+
'grid': {
83+
'color': (0.9, 0.9, 0.9, 1),
84+
'linewidth': 1.0,
85+
'linestyle': '-',
86+
},
87+
})
8388
else:
84-
self._axinfo.update(
85-
{'label': {'va': 'center',
86-
'ha': 'center'},
87-
'tick': {'inward_factor': 0.2,
88-
'outward_factor': 0.1,
89-
'linewidth': rcParams.get(
90-
adir + 'tick.major.width',
91-
rcParams['xtick.major.width'])},
92-
'axisline': {'linewidth': rcParams['axes.linewidth'],
93-
'color': rcParams['axes.edgecolor']},
94-
'grid': {'color': rcParams['grid.color'],
95-
'linewidth': rcParams['grid.linewidth'],
96-
'linestyle': rcParams['grid.linestyle']},
97-
})
89+
self._axinfo.update({
90+
'label': {'va': 'center', 'ha': 'center'},
91+
'tick': {
92+
'inward_factor': 0.2,
93+
'outward_factor': 0.1,
94+
'linewidth': {
95+
True: ( # major
96+
rcParams['xtick.major.width'] if adir in 'xz' else
97+
rcParams['ytick.major.width']),
98+
False: ( # minor
99+
rcParams['xtick.minor.width'] if adir in 'xz' else
100+
rcParams['ytick.minor.width']),
101+
}
102+
},
103+
'axisline': {
104+
'linewidth': rcParams['axes.linewidth'],
105+
'color': rcParams['axes.edgecolor'],
106+
},
107+
'grid': {
108+
'color': rcParams['grid.color'],
109+
'linewidth': rcParams['grid.linewidth'],
110+
'linestyle': rcParams['grid.linestyle'],
111+
},
112+
})
98113

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

@@ -135,11 +150,17 @@ def get_tick_positions(self):
135150
def get_major_ticks(self, numticks=None):
136151
ticks = maxis.XAxis.get_major_ticks(self, numticks)
137152
for t in ticks:
138-
t.tick1line.set_transform(self.axes.transData)
139-
t.tick2line.set_transform(self.axes.transData)
140-
t.gridline.set_transform(self.axes.transData)
141-
t.label1.set_transform(self.axes.transData)
142-
t.label2.set_transform(self.axes.transData)
153+
for obj in [
154+
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
155+
obj.set_transform(self.axes.transData)
156+
return ticks
157+
158+
def get_minor_ticks(self, numticks=None):
159+
ticks = maxis.XAxis.get_minor_ticks(self, numticks)
160+
for t in ticks:
161+
for obj in [
162+
t.tick1line, t.tick2line, t.gridline, t.label1, t.label2]:
163+
obj.set_transform(self.axes.transData)
143164
return ticks
144165

145166
def set_pane_pos(self, xys):
@@ -385,7 +406,8 @@ def draw(self, renderer):
385406
lx, ly, lz = proj3d.proj_transform(*pos, renderer.M)
386407

387408
tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly))
388-
tick.tick1line.set_linewidth(info['tick']['linewidth'])
409+
tick.tick1line.set_linewidth(
410+
info['tick']['linewidth'][tick._major])
389411
tick.draw(renderer)
390412

391413
renderer.close_group('axis3d')
Loading

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,3 +986,14 @@ def test_quiver3D_smoke(fig_test, fig_ref):
986986
for fig, length in zip((fig_ref, fig_test), (1, 1.0)):
987987
ax = fig.gca(projection="3d")
988988
ax.quiver(x, y, z, u, v, w, length=length, pivot=pivot)
989+
990+
991+
@image_comparison(["minor_ticks.png"], style="default")
992+
def test_minor_ticks():
993+
ax = plt.figure().add_subplot(projection="3d")
994+
ax.set_xticks([0.25], minor=True)
995+
ax.set_xticklabels(["quarter"], minor=True)
996+
ax.set_yticks([0.33], minor=True)
997+
ax.set_yticklabels(["third"], minor=True)
998+
ax.set_zticks([0.50], minor=True)
999+
ax.set_zticklabels(["half"], minor=True)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.