Skip to content

Commit

Permalink
Merge pull request matplotlib#1 from CSC-D01-Winter-2015/Issue-#3610
Browse files Browse the repository at this point in the history
  • Loading branch information
omfgitsjack committed Feb 28, 2015
2 parents f4f872b + 8d3a33d commit e24dec1
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 11 deletions.
12 changes: 12 additions & 0 deletions Issue3610.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
print(mpl.__file__)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('X LABEL', labelpad=-.5)
ax.set_ylabel('Y LABEL')
ax.yaxis._axinfo['label']['space_factor'] = 3
ax.set_zlabel('Z LABEL')
ax.zaxis.labelpad = -2
plt.show()
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,7 @@ def tk_window_focus():
'mpl_toolkits.tests.test_mplot3d',
'mpl_toolkits.tests.test_axes_grid1',
'mpl_toolkits.tests.test_axes_grid',
'mpl_toolkits.tests.test_mplot3d_axes'
]


Expand Down
5 changes: 0 additions & 5 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,12 +1182,7 @@ def _on_move(self, event):
def set_zlabel(self, zlabel, fontdict=None, labelpad=None, **kwargs):
'''
Set zlabel. See doc for :meth:`set_ylabel` for description.
.. note::
Currently, *labelpad* does not have an effect on the labels.
'''
# FIXME: With a rework of axis3d.py, the labelpad should work again
# At that point, remove the above message in the docs.
if labelpad is not None : self.zaxis.labelpad = labelpad
return self.zaxis.set_label_text(zlabel, fontdict, **kwargs)

Expand Down
25 changes: 19 additions & 6 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def tick_update_position(tick, tickxs, tickys, labelpos):
tick.gridline.set_data(0, 0)

class Axis(maxis.XAxis):

# These points from the unit cube make up the x, y and z-planes
_PLANES = (
(0, 3, 7, 4), (1, 2, 6, 5), # yz planes
Expand All @@ -69,9 +69,12 @@ class Axis(maxis.XAxis):
'z': {'i': 2, 'tickdir': 0, 'juggled': (0, 2, 1),
'color': (0.925, 0.925, 0.925, 0.5)},
}
# Default value for label padding for 3d axes, replaced hard coded value
DEFAULTLABELPAD = 1.6

def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
# adir identifies which axes this is

self.adir = adir
# data and viewing intervals for this direction
self.d_interval = d_intervalx
Expand All @@ -80,7 +83,7 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
# This is a temporary member variable.
# Do not depend on this existing in future releases!
self._axinfo = self._AXINFO[adir].copy()
self._axinfo.update({'label' : {'space_factor': 1.6,
self._axinfo.update({'label' : {'space_factor': self.DEFAULTLABELPAD,
'va': 'center',
'ha': 'center'},
'tick' : {'inward_factor': 0.2,
Expand All @@ -91,10 +94,13 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
'grid' : {'color': (0.9, 0.9, 0.9, 1),
'linewidth': 1.0},
})


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


# labelpad is the conventional way to deal with label padding
# change it's default value from 5 to 1.6 for mplot3d
self.labelpad = self.DEFAULTLABELPAD
self.set_rotate_label(kwargs.get('rotate_label', None))


Expand Down Expand Up @@ -264,8 +270,15 @@ def draw(self, renderer):
self.axes.transAxes.transform([peparray[0:2, 0]]))[0]

lxyz = 0.5*(edgep1 + edgep2)

labeldeltas = info['label']['space_factor'] * deltas
# Check to see if space_factor has been changed rather than
# removing it completely and only using self.labelpad which
# would break any existing code that use the current workaround
# to change label padding. As indicated in the comments above.
# _axinfo is only temporary at which point this line would be
# removed.
if (info['label']['space_factor'] != self.DEFAULTLABELPAD):
self.labelpad = info['label']['space_factor']
labeldeltas = self.labelpad * deltas
axmask = [True, True, True]
axmask[index] = False
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d_axes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from mpl_toolkits.mplot3d import Axes3D, axes3d
import matplotlib.pyplot as plt
from nose.tools import assert_equal, assert_raises, assert_false, assert_true

from matplotlib.testing.decorators import cleanup, image_comparison

@image_comparison(baseline_images=['3Dlabelpad_default'], remove_text=True,
extensions=['png', 'pdf'])
def test_axes_labelpad_default():
fig = plt.figure()
ax = fig.gca(projection='3d')
z = [0,1]
x = [0,1]
y = [0,1]
ax.plot(x, y, z)
ax.set_xlabel('X LABEL')
ax.set_ylabel('Y LABEL')
ax.set_zlabel('Z LABEL')
plt.draw()
assert_equal(ax.xaxis.labelpad, ax.xaxis.DEFAULTLABELPAD)
assert_equal(ax.yaxis.labelpad, ax.yaxis.DEFAULTLABELPAD)
assert_equal(ax.zaxis.labelpad, ax.zaxis.DEFAULTLABELPAD)

@image_comparison(baseline_images=['3Dlabelpad'], remove_text=True,
extensions=['png', 'pdf'])
def test_axes_labelpad_image():
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlabel('X LABEL', labelpad=-.5)
ax.set_ylabel('Y LABEL')
ax.yaxis._axinfo['label']['space_factor'] = 3
ax.set_zlabel('Z LABEL')
ax.zaxis.labelpad = -2

@cleanup
def test_axes_labelpad():
fig = plt.figure()
ax = fig.gca(projection='3d')
z = [0,1]
x = [0,1]
y = [0,1]
ax.plot(x, y, z)
ax.set_xlabel('X LABEL', labelpad=3)
plt.draw()
assert_equal(ax.xaxis.labelpad, 3)

@cleanup
def test_axes_labelpad_oldmethod():
fig = plt.figure()
ax = fig.gca(projection='3d')
z = [0,1]
x = [0,1]
y = [0,1]
ax.plot(x, y, z)
ax.set_zlabel('Z LABEL')
ax.zaxis._axinfo['label']['space_factor'] = 3
plt.draw()
assert_equal(ax.zaxis.labelpad, 3)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 comments on commit e24dec1

Please sign in to comment.