From: <jd...@us...> - 2008-06-09 21:31:49
|
Revision: 5446 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5446&view=rev Author: jdh2358 Date: 2008-06-09 14:31:46 -0700 (Mon, 09 Jun 2008) Log Message: ----------- added text properties to users guide Modified Paths: -------------- trunk/matplotlib/doc/users/figures/pyplot_text.py trunk/matplotlib/doc/users/pyplot_tutorial.rst Added Paths: ----------- trunk/matplotlib/doc/users/figures/text_layout.py trunk/matplotlib/doc/users/text_props.rst Modified: trunk/matplotlib/doc/users/figures/pyplot_text.py =================================================================== --- trunk/matplotlib/doc/users/figures/pyplot_text.py 2008-06-09 21:01:33 UTC (rev 5445) +++ trunk/matplotlib/doc/users/figures/pyplot_text.py 2008-06-09 21:31:46 UTC (rev 5446) @@ -11,7 +11,7 @@ plt.xlabel('Smarts') plt.ylabel('Probability') plt.title('Histogram of IQ') -plt.text(85, .025, r'$\mu=100,\ \sigma=15$') +plt.text(60, .025, r'$\mu=100,\ \sigma=15$') plt.axis([40, 160, 0, 0.03]) plt.grid(True) Added: trunk/matplotlib/doc/users/figures/text_layout.py =================================================================== --- trunk/matplotlib/doc/users/figures/text_layout.py (rev 0) +++ trunk/matplotlib/doc/users/figures/text_layout.py 2008-06-09 21:31:46 UTC (rev 5446) @@ -0,0 +1,77 @@ +import matplotlib.pyplot as plt +import matplotlib.patches as patches + +# build a rectangle in axes coords +left, width = .25, .5 +bottom, height = .25, .5 +right = left + width +top = bottom + height + +fig = plt.figure() +ax = fig.add_subplot(111) + +# axes coordinates are 0,0 is bottom left and 1,1 is upper right +p = patches.Rectangle( + (left, bottom), width, height, + fill=False, transform=ax.transAxes, clip_on=False + ) + +ax.add_patch(p) + +ax.text(left, bottom, 'left top', + horizontalalignment='left', + verticalalignment='top', + transform=ax.transAxes) + +ax.text(left, bottom, 'left bottom', + horizontalalignment='left', + verticalalignment='bottom', + transform=ax.transAxes) + +ax.text(right, top, 'right bottom', + horizontalalignment='right', + verticalalignment='bottom', + transform=ax.transAxes) + +ax.text(right, top, 'right top', + horizontalalignment='right', + verticalalignment='top', + transform=ax.transAxes) + +ax.text(right, bottom, 'center top', + horizontalalignment='center', + verticalalignment='top', + transform=ax.transAxes) + +ax.text(left, 0.5*(bottom+top), 'right center', + horizontalalignment='right', + verticalalignment='center', + rotation='vertical', + transform=ax.transAxes) + +ax.text(left, 0.5*(bottom+top), 'left center', + horizontalalignment='left', + verticalalignment='center', + rotation='vertical', + transform=ax.transAxes) + +ax.text(0.5*(left+right), 0.5*(bottom+top), 'middle', + horizontalalignment='center', + verticalalignment='center', + fontsize=20, color='red', + transform=ax.transAxes) + +ax.text(right, 0.5*(bottom+top), 'centered', + horizontalalignment='center', + verticalalignment='center', + rotation='vertical', + transform=ax.transAxes) + +ax.text(left, top, 'rotated\nwith newlines', + horizontalalignment='center', + verticalalignment='center', + rotation=45, + transform=ax.transAxes) + +ax.set_axis_off() +plt.show() Modified: trunk/matplotlib/doc/users/pyplot_tutorial.rst =================================================================== --- trunk/matplotlib/doc/users/pyplot_tutorial.rst 2008-06-09 21:01:33 UTC (rev 5445) +++ trunk/matplotlib/doc/users/pyplot_tutorial.rst 2008-06-09 21:31:46 UTC (rev 5446) @@ -153,8 +153,8 @@ .. _multiple-figs-axes: -Working with multiple figure and axes -===================================== +Working with multiple figures and axes +====================================== Matlab, and :mod:`~matplotlib.pyplot`, have the concept of the current @@ -232,47 +232,9 @@ t = plt.xlabel('my data', fontsize=14, color='red') -The following font properties can be set +These properties are covered in more detail in :ref:`text-properties`. -========================== ============================================================================== -Property Value Type -========================== ============================================================================== -alpha float -backgroundcolor any matplotlib color -bbox rectangle prop dict plus key 'pad' which is a pad in points -clip_box a matplotlib.transform.Bbox instance -clip_on [True | False] -clip_path a Path instance and a Transform instance, a Patch -color any matplotlib color -family [ 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ] -fontproperties a matplotlib.font_manager.FontProperties instance -horizontalalignment or ha [ 'center' | 'right' | 'left' ] -label any string -linespacing float -multialignment ['left' | 'right' | 'center' ] -name or fontname string eg, ['Sans' | 'Courier' | 'Helvetica' ...] -picker [None|float|boolean|callable] -position (x,y) -rotation [ angle in degrees 'vertical' | 'horizontal' -size or fontsize [ size in points | relative size eg 'smaller', 'x-large' ] -style or fontstyle [ 'normal' | 'italic' | 'oblique'] -text string or anything printable with '%s' conversion -transform a matplotlib.transform transformation instance -variant [ 'normal' | 'small-caps' ] -verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' ] -visible [True | False] -weight or fontweight [ 'normal' | 'bold' | 'heavy' | 'light' | 'ultrabold' | 'ultralight'] -x float -y float -zorder any number -========================== ============================================================================== - -See `align_text <http://matplotlib.sf.net/screenshots.html#align_text>`_ for -examples of how to control the alignment and orientation of text. - - - Using mathematical expressions in text -------------------------------------- Added: trunk/matplotlib/doc/users/text_props.rst =================================================================== --- trunk/matplotlib/doc/users/text_props.rst (rev 0) +++ trunk/matplotlib/doc/users/text_props.rst 2008-06-09 21:31:46 UTC (rev 5446) @@ -0,0 +1,63 @@ +.. _text-properties: + +Text properties and layout +========================== + +The :class:`matplotlib.text.Text` instances have a variety of +properties which can be configured via keyword arguments to the text +commands (eg :func:`~matplotlib.pyplot.title`, +:func:`~matplotlib.pyplot.xlabel` and :func:`~matplotlib.pyplot.text`). + +========================== ============================================================================== +Property Value Type +========================== ============================================================================== +alpha float +backgroundcolor any matplotlib color +bbox rectangle prop dict plus key 'pad' which is a pad in points +clip_box a matplotlib.transform.Bbox instance +clip_on [True | False] +clip_path a Path instance and a Transform instance, a Patch +color any matplotlib color +family [ 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ] +fontproperties a matplotlib.font_manager.FontProperties instance +horizontalalignment or ha [ 'center' | 'right' | 'left' ] +label any string +linespacing float +multialignment ['left' | 'right' | 'center' ] +name or fontname string eg, ['Sans' | 'Courier' | 'Helvetica' ...] +picker [None|float|boolean|callable] +position (x,y) +rotation [ angle in degrees 'vertical' | 'horizontal' +size or fontsize [ size in points | relative size eg 'smaller', 'x-large' ] +style or fontstyle [ 'normal' | 'italic' | 'oblique'] +text string or anything printable with '%s' conversion +transform a matplotlib.transform transformation instance +variant [ 'normal' | 'small-caps' ] +verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' ] +visible [True | False] +weight or fontweight [ 'normal' | 'bold' | 'heavy' | 'light' | 'ultrabold' | 'ultralight'] +x float +y float +zorder any number +========================== ============================================================================== + + +You can layout text with the alignment arguments +``horizontalalignment``, ``verticalalignment``, and +``multialignment``. ``horizontalalignment`` controls whether the x +positional argument for the text indicates the left, center or right +side of the text bounding box. ``verticalalignment`` controls whether +the y positional argument for the text indicates the bottom, center or +top side of the text bounding box. ``multialignment``, for newline +separated strings only, controls whether the different lines are left, +center or right justified. Here is an example which uses the +:func:`~matplotlib.pyplot.text` command to show the various alignment +possibilities. The use of ``transform=ax.transAxes`` throughout the +code indicates that the coordinates are given relative to the axes +bounding box, with 0,0 being the lower left of the axes and 1,1 the +upper right. + +.. literalinclude:: figures/text_layout.py + +.. image:: figures/text_layout.png + :scale: 50 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |