Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6412735

Browse files
committed
Makes 3D labelpads behave more like 2D ones
1 parent 47811bc commit 6412735

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class Axis(maxis.XAxis):
7070
'color': (0.925, 0.925, 0.925, 0.5)},
7171
}
7272

73+
# Factors for converting 2D labelpad properties to 3D
74+
# Determined by trial and error
75+
_DELTAS_PER_POINT = 0.05
76+
_DEFAULT_LABEL_OFFSET = 1.35 # In deltas
77+
7378
def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
7479
# adir identifies which axes this is
7580
self.adir = adir
@@ -94,8 +99,6 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
9499

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

97-
self.labelpad = 1.6
98-
99102
self.set_rotate_label(kwargs.get('rotate_label', None))
100103

101104

@@ -266,7 +269,8 @@ def draw(self, renderer):
266269

267270
lxyz = 0.5*(edgep1 + edgep2)
268271

269-
labeldeltas = self.labelpad * deltas
272+
labeldeltas = (self.labelpad * self._DELTAS_PER_POINT +
273+
self._DEFAULT_LABEL_OFFSET) * deltas
270274
axmask = [True, True, True]
271275
axmask[index] = False
272276
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
-8 Bytes
Loading

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,21 @@ def test_quiver3d_pivot_tail():
236236

237237
@image_comparison(baseline_images=['axes3d_labelpad'], extensions=['png'])
238238
def test_axes3d_labelpad():
239+
from nose.tools import assert_equal
240+
from matplotlib import rcParams
241+
239242
fig = plt.figure()
240243
ax = Axes3D(fig)
241-
242-
# labelpad can be set in constructor
243-
ax.set_xlabel('X LABEL', labelpad=1.3)
244+
# labelpad respects rcParams
245+
assert_equal(ax.xaxis.labelpad, rcParams['axes.labelpad'])
246+
# labelpad can be set in set_label
247+
ax.set_xlabel('X LABEL', labelpad=3)
248+
assert_equal(ax.xaxis.labelpad, 3)
244249
ax.set_ylabel('Y LABEL')
245250
ax.set_zlabel('Z LABEL')
246251
# or manually
247-
ax.yaxis.labelpad = 3
248-
ax.zaxis.labelpad = -1
252+
ax.yaxis.labelpad = 20
253+
ax.zaxis.labelpad = -40
249254

250255

251256
if __name__ == '__main__':

0 commit comments

Comments
 (0)