Revision: 8794 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8794&view=rev Author: weathergod Date: 2010-11-12 16:10:21 +0000 (Fri, 12 Nov 2010)
Log Message: ----------- 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. Modified Paths: -------------- branches/v1_0_maint/CHANGELOG branches/v1_0_maint/lib/mpl_toolkits/mplot3d/axis3d.py Modified: branches/v1_0_maint/CHANGELOG =================================================================== --- branches/v1_0_maint/CHANGELOG 2010-11-12 14:59:38 UTC (rev 8793) +++ branches/v1_0_maint/CHANGELOG 2010-11-12 16:10:21 UTC (rev 8794) @@ -1,3 +1,5 @@ +2010-11-12 Fixed the placement and angle of axis labels in 3D plots. - BVR + 2010-11-07 New rc parameters examples.download and examples.directory allow bypassing the download mechanism in get_sample_data. - JKS Modified: branches/v1_0_maint/lib/mpl_toolkits/mplot3d/axis3d.py =================================================================== --- branches/v1_0_maint/lib/mpl_toolkits/mplot3d/axis3d.py 2010-11-12 14:59:38 UTC (rev 8793) +++ branches/v1_0_maint/lib/mpl_toolkits/mplot3d/axis3d.py 2010-11-12 16:10:21 UTC (rev 8794) @@ -91,6 +91,7 @@ self.gridlines = art3d.Line3DCollection([], ) self.axes._set_artist_props(self.gridlines) self.axes._set_artist_props(self.label) + # Need to be able to place the label at the correct location self.label._transform = self.axes.transData self.set_rotate_label(kwargs.get('rotate_label', None)) @@ -209,13 +210,23 @@ xyz0.append(coord) # Draw labels - dy = pep[1][1] - pep[1][0] - dx = pep[0][1] - pep[0][0] + peparray = np.asanyarray(pep) + # The transAxes transform is used because the Text object + # rotates the text relative to the display coordinate system. + # Therefore, if we want the labels to remain parallel to the + # axis regardless of the aspect ratio, we need to convert the + # edge points of the plane to display coordinates and calculate + # an angle from that. + # TODO: Maybe Text objects should handle this themselves? + dx, dy = (self.axes.transAxes.transform(peparray[0:2, 1]) - + self.axes.transAxes.transform(peparray[0:2, 0])) lxyz = 0.5*(edgep1 + edgep2) labeldeltas = 1.3 * deltas - lxyz = move_from_center(lxyz, centers, labeldeltas) + axmask = [True, True, True] + axmask[index] = False + lxyz = move_from_center(lxyz, centers, labeldeltas, axmask) tlx, tly, tlz = proj3d.proj_transform(lxyz[0], lxyz[1], lxyz[2], \ renderer.M) self.label.set_position((tlx, tly)) @@ -223,6 +234,7 @@ angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx))) self.label.set_rotation(angle) self.label.set_va('center') + self.label.set_ha('center') self.label.draw(renderer) # Grid points at end of one plane This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Centralized Desktop Delivery: Dell and VMware Reference Architecture Simplifying enterprise desktop deployment and management using Dell EqualLogic storage and VMware View: A highly scalable, end-to-end client virtualization framework. Read more! http://p.sf.net/sfu/dell-eql-dev2dev _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins