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

Skip to content

Commit fbda603

Browse files
committed
Fixed a bug in axis3d.py which caused axis labels to not be centered along the axis as well as correctly calculating the rotation angle needed to keep the axis label parallel to the axis irrespectively of the plot's aspect ratio.
svn path=/branches/v1_0_maint/; revision=8794
1 parent 94abf2f commit fbda603

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2010-11-12 Fixed the placement and angle of axis labels in 3D plots. - BVR
2+
13
2010-11-07 New rc parameters examples.download and examples.directory
24
allow bypassing the download mechanism in get_sample_data.
35
- JKS

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(self, adir, v_intervalx, d_intervalx, axes, *args, **kwargs):
9191
self.gridlines = art3d.Line3DCollection([], )
9292
self.axes._set_artist_props(self.gridlines)
9393
self.axes._set_artist_props(self.label)
94+
# Need to be able to place the label at the correct location
9495
self.label._transform = self.axes.transData
9596
self.set_rotate_label(kwargs.get('rotate_label', None))
9697

@@ -209,20 +210,31 @@ def draw(self, renderer):
209210
xyz0.append(coord)
210211

211212
# Draw labels
212-
dy = pep[1][1] - pep[1][0]
213-
dx = pep[0][1] - pep[0][0]
213+
peparray = np.asanyarray(pep)
214+
# The transAxes transform is used because the Text object
215+
# rotates the text relative to the display coordinate system.
216+
# Therefore, if we want the labels to remain parallel to the
217+
# axis regardless of the aspect ratio, we need to convert the
218+
# edge points of the plane to display coordinates and calculate
219+
# an angle from that.
220+
# TODO: Maybe Text objects should handle this themselves?
221+
dx, dy = (self.axes.transAxes.transform(peparray[0:2, 1]) -
222+
self.axes.transAxes.transform(peparray[0:2, 0]))
214223

215224
lxyz = 0.5*(edgep1 + edgep2)
216225

217226
labeldeltas = 1.3 * deltas
218-
lxyz = move_from_center(lxyz, centers, labeldeltas)
227+
axmask = [True, True, True]
228+
axmask[index] = False
229+
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
219230
tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \
220231
renderer.M)
221232
self.label.set_position((tlx, tly))
222233
if self.get_rotate_label(self.label.get_text()):
223234
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
224235
self.label.set_rotation(angle)
225236
self.label.set_va('center')
237+
self.label.set_ha('center')
226238
self.label.draw(renderer)
227239

228240
# Grid points at end of one plane

0 commit comments

Comments
 (0)