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

Skip to content

Commit 470e595

Browse files
committed
Merged revisions 8794 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v1_0_maint ........ r8794 | weathergod | 2010-11-12 10:10:21 -0600 (Fri, 12 Nov 2010) | 2 lines 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=/trunk/matplotlib/; revision=8795
1 parent e9bc21f commit 470e595

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

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
@@ -96,6 +96,7 @@ def init3d(self):
9696
self.gridlines = art3d.Line3DCollection([], )
9797
self.axes._set_artist_props(self.gridlines)
9898
self.axes._set_artist_props(self.label)
99+
# Need to be able to place the label at the correct location
99100
self.label._transform = self.axes.transData
100101

101102
def get_tick_positions(self):
@@ -215,20 +216,31 @@ def draw(self, renderer):
215216
xyz0.append(coord)
216217

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

221230
lxyz = 0.5*(edgep1 + edgep2)
222231

223232
labeldeltas = 1.3 * deltas
224-
lxyz = move_from_center(lxyz, centers, labeldeltas)
233+
axmask = [True, True, True]
234+
axmask[index] = False
235+
lxyz = move_from_center(lxyz, centers, labeldeltas, axmask)
225236
tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \
226237
renderer.M)
227238
self.label.set_position((tlx, tly))
228239
if self.get_rotate_label(self.label.get_text()):
229240
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
230241
self.label.set_rotation(angle)
231242
self.label.set_va('center')
243+
self.label.set_ha('center')
232244
self.label.draw(renderer)
233245

234246
if len(xyz0) > 0:

0 commit comments

Comments
 (0)