Revision: 7215
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7215&view=rev
Author: leejjoon
Date: 2009-06-13 16:54:31 +0000 (Sat, 13 Jun 2009)
Log Message:
-----------
Introduce a rotation_mode property for the Text artist
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/text.py
Added Paths:
-----------
trunk/matplotlib/examples/pylab_examples/demo_text_rotation_mode.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2009-06-13 12:09:29 UTC (rev 7214)
+++ trunk/matplotlib/CHANGELOG 2009-06-13 16:54:31 UTC (rev 7215)
@@ -1,3 +1,6 @@
+2009-06-13 Introduce a rotation_mode property for the Text artist. See
+ examples/pylab_examples/demo_text_rotation_mode.py -JJL
+
2009-06-07 add support for bz2 files per sf support request 2794556 -
JDH
Added: trunk/matplotlib/examples/pylab_examples/demo_text_rotation_mode.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/demo_text_rotation_mode.py
(rev 0)
+++ trunk/matplotlib/examples/pylab_examples/demo_text_rotation_mode.py
2009-06-13 16:54:31 UTC (rev 7215)
@@ -0,0 +1,45 @@
+
+#clf()
+from mpl_toolkits.axes_grid.axes_grid import AxesGrid
+
+def test_rotation_mode(fig, mode, subplot_location):
+ ha_list = "left center right".split()
+ va_list = "top center baseline bottom".split()
+ grid = AxesGrid(fig, subplot_location,
+ nrows_ncols=(len(va_list), len(ha_list)),
+ share_all=True, aspect=True, #label_mode='1',
+ cbar_mode=None)
+
+ for ha, ax in zip(ha_list, grid.axes_row[-1]):
+ ax.axis["bottom"].label.set_text(ha)
+
+ grid.axes_row[0][1].set_title(mode, size="large")
+
+ for va, ax in zip(va_list, grid.axes_column[0]):
+ ax.axis["left"].label.set_text(va)
+
+ i = 0
+ for va in va_list:
+ for ha in ha_list:
+ ax = grid[i]
+ for axis in ax.axis.values():
+ axis.toggle(ticks=False, ticklabels=False)
+
+ ax.text(0.5, 0.5, "Tpg",
+ size="large", rotation=40,
+ bbox=dict(boxstyle="square,pad=0.",
+ ec="none", fc="0.5", alpha=0.5),
+ ha=ha, va=va,
+ rotation_mode=mode)
+ ax.axvline(0.5)
+ ax.axhline(0.5)
+ i += 1
+
+if 1:
+ import matplotlib.pyplot as plt
+ fig = plt.figure(1, figsize=(5.5,4 ))
+ fig.clf()
+
+ test_rotation_mode(fig, "default", 121)
+ test_rotation_mode(fig, "anchor", 122)
+ plt.show()
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2009-06-13 12:09:29 UTC (rev
7214)
+++ trunk/matplotlib/lib/matplotlib/text.py 2009-06-13 16:54:31 UTC (rev
7215)
@@ -69,6 +69,7 @@
name or fontname string eg, ['Sans' | 'Courier' | 'Helvetica'
...]
position (x,y)
rotation [ angle in degrees 'vertical' | 'horizontal'
+ rotation_mode [ None | 'anchor']
size or fontsize [ size in points | relative size eg 'smaller',
'x-large' ]
style or fontstyle [ 'normal' | 'italic' | 'oblique']
text string
@@ -144,6 +145,7 @@
fontproperties=None, # defaults to FontProperties()
rotation=None,
linespacing=None,
+ rotation_mode=None,
**kwargs
):
"""
@@ -175,6 +177,7 @@
if linespacing is None:
linespacing = 1.2 # Maybe use rcParam later.
self._linespacing = linespacing
+ self.set_rotation_mode(rotation_mode)
self.update(kwargs)
#self.set_bbox(dict(pad=0))
@@ -214,6 +217,24 @@
'return the text angle as float in degrees'
return get_rotation(self._rotation) # string_or_number -> number
+ def set_rotation_mode(self, m):
+ """
+ set text rotation mode. If "anchor", the un-rotated text
+ will first aligned according to their *ha* and
+ *va*, and then will be rotated with the alignement
+ reference point as a origin. If None (default), the text will be
+ rotated first then will be aligned.
+ """
+ if m is None or m in ["anchor", "default"]:
+ self._rotation_mode = m
+ else:
+ raise ValueError("Unknown rotation_mode : %s" % repr(m))
+
+ def get_rotation_mode(self):
+ "get text rotation mode"
+ return self._rotation_mode
+
+
def update_from(self, other):
'Copy properties from other to self'
Artist.update_from(self, other)
@@ -268,7 +289,7 @@
# For multiline text, increase the line spacing when the
# text net-height(excluding baseline) is larger than that
# of a "l" (e.g., use of superscripts), which seems
- # what TeX does.
+ # what TeX does.
d_yoffset = max(0, (h-d)-(lp_h-lp_bl))
@@ -315,17 +336,34 @@
halign = self._horizontalalignment
valign = self._verticalalignment
- # compute the text location in display coords and the offsets
- # necessary to align the bbox with that location
- if halign=='center': offsetx = (xmin + width/2.0)
- elif halign=='right': offsetx = (xmin + width)
- else: offsetx = xmin
+ rotation_mode = self.get_rotation_mode()
+ if rotation_mode != "anchor":
+ # compute the text location in display coords and the offsets
+ # necessary to align the bbox with that location
+ if halign=='center': offsetx = (xmin + width/2.0)
+ elif halign=='right': offsetx = (xmin + width)
+ else: offsetx = xmin
- if valign=='center': offsety = (ymin + height/2.0)
- elif valign=='top': offsety = (ymin + height)
- elif valign=='baseline': offsety = (ymin + height) - baseline
- else: offsety = ymin
+ if valign=='center': offsety = (ymin + height/2.0)
+ elif valign=='top': offsety = (ymin + height)
+ elif valign=='baseline': offsety = (ymin + height) - baseline
+ else: offsety = ymin
+ else:
+ xmin1, ymin1 = cornersHoriz[0]
+ xmax1, ymax1 = cornersHoriz[2]
+ if halign=='center': offsetx = (xmin1 + xmax1)/2.0
+ elif halign=='right': offsetx = xmax1
+ else: offsetx = xmin1
+
+ if valign=='center': offsety = (ymin1 + ymax1)/2.0
+ elif valign=='top': offsety = ymax1
+ elif valign=='baseline': offsety = ymax1 - baseline
+ else: offsety = ymin1
+
+ offsetx, offsety = M.transform_point((offsetx, offsety))
+
+
xmin -= offsetx
ymin -= offsety
@@ -1562,8 +1600,8 @@
See :meth:`set_annotation_clip` for the meaning of return values.
"""
return self._annotation_clip
-
+
def update_positions(self, renderer):
"Update the pixel positions of the annotated point and the text."
xy_pixel = self._get_position_xy(renderer)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins