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

Skip to content

Refactors axis3d.py to address issue #3610 #3787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 28, 2015
6 changes: 6 additions & 0 deletions doc/users/whats_new/axis3d.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fixed labelpad in Axis3D
```````````````````````````````````

Axis3D now looks at xaxis.labelpad (from rcParams or set by
set_xlabel('X LABEL', labelpad=30) or ax.zaxis.labelpad = 20)
to determine the position of axis labels in 3D plots.
4 changes: 0 additions & 4 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,11 +1180,7 @@ 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
19 changes: 13 additions & 6 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,10 @@ 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,
'va': 'center',
self._axinfo.update({'label' : {'va': 'center',
'ha': 'center'},
'tick' : {'inward_factor': 0.2,
'outward_factor': 0.1},
'ticklabel': {'space_factor': 0.7},
'axisline': {'linewidth': 0.75,
'color': (0, 0, 0, 1)},
'grid' : {'color': (0.9, 0.9, 0.9, 1),
Expand Down Expand Up @@ -265,7 +263,14 @@ def draw(self, renderer):

lxyz = 0.5*(edgep1 + edgep2)

labeldeltas = info['label']['space_factor'] * deltas
# A rough estimate; points are ambiguous since 3D plots rotate
ax_scale = self.axes.bbox.size / self.figure.bbox.size
ax_inches = np.multiply(ax_scale, self.figure.get_size_inches())
ax_points_estimate = sum(72. * ax_inches)
deltas_per_point = 48. / ax_points_estimate
default_offset = 21.
labeldeltas = (self.labelpad + default_offset) * deltas_per_point\
* deltas
axmask = [True, True, True]
axmask[index] = False
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
Expand Down Expand Up @@ -394,8 +399,10 @@ def draw(self, renderer):
renderer.M)

# Get position of label
labeldeltas = [info['ticklabel']['space_factor'] * x for
x in deltas]
default_offset = 8. # A rough estimate
labeldeltas = (tick.get_pad() + default_offset) * deltas_per_point\
* deltas

axmask = [True, True, True]
axmask[index] = False
pos[tickdir] = edgep1[tickdir]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ def test_quiver3d_pivot_tail():

ax.quiver(x, y, z, u, v, w, length=0.1, pivot='tail')


@image_comparison(baseline_images=['axes3d_labelpad'], extensions=['png'])
def test_axes3d_labelpad():
from nose.tools import assert_equal
from matplotlib import rcParams

fig = plt.figure()
ax = Axes3D(fig)
# labelpad respects rcParams
assert_equal(ax.xaxis.labelpad, rcParams['axes.labelpad'])
# labelpad can be set in set_label
ax.set_xlabel('X LABEL', labelpad=10)
assert_equal(ax.xaxis.labelpad, 10)
ax.set_ylabel('Y LABEL')
ax.set_zlabel('Z LABEL')
# or manually
ax.yaxis.labelpad = 20
ax.zaxis.labelpad = -40

# Tick labels also respect tick.pad (also from rcParams)
for i, tick in enumerate(ax.yaxis.get_major_ticks()):
tick.set_pad(tick.get_pad() - i * 5)


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