Skip to content

Commit ac35c68

Browse files
committed
Added the ability for 3d plots to display the axis ticker offsets.
This should address bug 3137231. svn path=/trunk/matplotlib/; revision=8877
1 parent bf7ca4c commit ac35c68

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2011-01-03 Added display of ticker offset to 3d plots. - BVR
2+
13
2011-01-03 Turn off tick labeling on interior subplots for
24
pyplots.subplots when sharex/sharey is True. - JDH
35

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ 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+
self.axes._set_artist_props(self.offsetText)
99100
# Need to be able to place the label at the correct location
100101
self.label._transform = self.axes.transData
102+
self.offsetText._transform = self.axes.transData
101103

102104
def get_tick_positions(self):
103105
majorLocs = self.major.locator()
@@ -205,6 +207,7 @@ def draw(self, renderer):
205207
edgep2 = edgep1.copy()
206208
edgep2[juggled[1]] = get_flip_min_max(edgep2, juggled[1], mins, maxs)
207209
pep = proj3d.proj_trans_points([edgep1, edgep2], renderer.M)
210+
centpt = proj3d.proj_transform(centers[0], centers[1], centers[2], renderer.M)
208211
self.line.set_data((pep[0][0], pep[0][1]), (pep[1][0], pep[1][1]))
209212
self.line.draw(renderer)
210213

@@ -243,6 +246,75 @@ def draw(self, renderer):
243246
self.label.set_ha('center')
244247
self.label.draw(renderer)
245248

249+
250+
# Draw Offset text
251+
252+
# Which of the two edge points do we want to
253+
# use for locating the offset text?
254+
if juggled[2] == 2 :
255+
outeredgep = edgep1
256+
outerindex = 0
257+
else :
258+
outeredgep = edgep2
259+
outerindex = 1
260+
261+
pos = copy.copy(outeredgep)
262+
pos = move_from_center(pos, centers, labeldeltas, axmask)
263+
olx, oly, olz = proj3d.proj_transform(pos[0], pos[1], pos[2], renderer.M)
264+
self.offsetText.set_text( self.major.formatter.get_offset() )
265+
self.offsetText.set_position( (olx, oly) )
266+
angle = art3d.norm_text_angle(math.degrees(math.atan2(dy, dx)))
267+
self.offsetText.set_rotation(angle)
268+
# Must set rotation mode to "anchor" so that
269+
# the alignment point is used as the "fulcrum" for rotation.
270+
self.offsetText.set_rotation_mode('anchor')
271+
272+
#-----------------------------------------------------------------------
273+
# Note: the following statement for determining the proper alignment of
274+
# the offset text. This was determined entirely by trial-and-error
275+
# and should not be in any way considered as "the way". There are
276+
# still some edge cases where alignment is not quite right, but
277+
# this seems to be more of a geometry issue (in other words, I
278+
# might be using the wrong reference points).
279+
#
280+
# (TT, FF, TF, FT) are the shorthand for the tuple of
281+
# (centpt[info['tickdir']] <= peparray[info['tickdir'], outerindex],
282+
# centpt[index] <= peparray[index, outerindex])
283+
#
284+
# Three-letters (e.g., TFT, FTT) are short-hand for the array
285+
# of bools from the variable 'highs'.
286+
# ---------------------------------------------------------------------
287+
if centpt[info['tickdir']] > peparray[info['tickdir'], outerindex] :
288+
# if FT and if highs has an even number of Trues
289+
if (centpt[index] <= peparray[index, outerindex]
290+
and ((len(highs.nonzero()[0]) % 2) == 0)) :
291+
# Usually, this means align right, except for the FTT case,
292+
# in which offset for axis 1 and 2 are aligned left.
293+
if highs.tolist() == [False, True, True] and index in (1, 2) :
294+
align = 'left'
295+
else :
296+
align = 'right'
297+
else :
298+
# The FF case
299+
align = 'left'
300+
else :
301+
# if TF and if highs has an even number of Trues
302+
if (centpt[index] > peparray[index, outerindex]
303+
and ((len(highs.nonzero()[0]) % 2) == 0)) :
304+
# Usually mean align left, except if it is axis 2
305+
if index == 2 :
306+
align = 'right'
307+
else :
308+
align = 'left'
309+
else :
310+
# The TT case
311+
align = 'right'
312+
313+
self.offsetText.set_va('center')
314+
self.offsetText.set_ha(align)
315+
self.offsetText.draw(renderer)
316+
317+
# Draw grid lines
246318
if len(xyz0) > 0:
247319
# Grid points at end of one plane
248320
xyz1 = copy.deepcopy(xyz0)

0 commit comments

Comments
 (0)