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

Skip to content

NF - Text numeric values for ha and va #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from matplotlib import rcParams
import matplotlib.artist as artist
from matplotlib.artist import Artist
from matplotlib.cbook import is_string_like, maxdict
from matplotlib.cbook import is_string_like, maxdict, is_numlike
from matplotlib import docstring
from matplotlib.font_manager import FontProperties
from matplotlib.patches import bbox_artist, YAArrow, FancyBboxPatch, \
Expand Down Expand Up @@ -69,21 +69,21 @@ def get_rotation(rotation):
family [ 'serif' | 'sans-serif' | 'cursive' | 'fantasy' | 'monospace' ]
figure a matplotlib.figure.Figure instance
fontproperties a matplotlib.font_manager.FontProperties instance
horizontalalignment or ha [ 'center' | 'right' | 'left' ]
horizontalalignment or ha [ 'center' | 'right' | 'left' | fraction text width from left ]
label any string
linespacing float
lod [True | False]
multialignment ['left' | 'right' | 'center' ]
name or fontname string eg, ['Sans' | 'Courier' | 'Helvetica' ...]
position (x,y)
rotation [ angle in degrees 'vertical' | 'horizontal'
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
transform a matplotlib.transform transformation instance
variant [ 'normal' | 'small-caps' ]
verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' ]
verticalalignment or va [ 'center' | 'top' | 'bottom' | 'baseline' | fraction text height from bottom ]
visible [True | False]
weight or fontweight [ 'normal' | 'bold' | 'heavy' | 'light' | 'ultrabold' | 'ultralight']
x float
Expand Down Expand Up @@ -378,25 +378,29 @@ def get_text_width_height_descent(*kl, **kwargs):
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)
if halign=='center': offsetx = (xmin + width*0.5)
elif halign=='right': offsetx = (xmin + width)
elif is_numlike(halign): offsetx = xmin + halign * (xmax - xmin)
else: offsetx = xmin

if valign=='center': offsety = (ymin + height/2.0)
if valign=='center': offsety = (ymin + height*0.5)
elif valign=='top': offsety = (ymin + height)
elif valign=='baseline': offsety = (ymin + height) - baseline
elif is_numlike(valign): offsety = ymin + valign * (ymax - ymin)
else: offsety = ymin
else:
xmin1, ymin1 = cornersHoriz[0]
xmax1, ymax1 = cornersHoriz[2]

if halign=='center': offsetx = (xmin1 + xmax1)/2.0
if halign=='center': offsetx = (xmin1 + xmax1)*0.5
elif halign=='right': offsetx = xmax1
elif is_numlike(halign): offsetx = xmin1 + halign * (xmax1 - xmin1)
else: offsetx = xmin1

if valign=='center': offsety = (ymin1 + ymax1)/2.0
if valign=='center': offsety = (ymin1 + ymax1)*0.5
elif valign=='top': offsety = ymax1
elif valign=='baseline': offsety = ymax1 - baseline
elif is_numlike(valign): offsety = ymin1 + valign * (ymax1 - ymin1)
else: offsety = ymin1

offsetx, offsety = M.transform_point((offsetx, offsety))
Expand Down Expand Up @@ -796,11 +800,11 @@ def set_horizontalalignment(self, align):
"""
Set the horizontal alignment to one of

ACCEPTS: [ 'center' | 'right' | 'left' ]
ACCEPTS: [ 'center' | 'right' | 'left' | fraction text width from left ]
"""
legal = ('center', 'right', 'left')
if align not in legal:
raise ValueError('Horizontal alignment must be one of %s' % str(legal))
if align not in legal and not is_numlike(align):
raise ValueError('Horizontal alignment must be numeric or one of %s' % str(legal))
self._horizontalalignment = align

def set_ma(self, align):
Expand All @@ -811,7 +815,7 @@ def set_ma(self, align):
def set_multialignment(self, align):
"""
Set the alignment for multiple lines layout. The layout of the
bounding box of all the lines is determined bu the horizontalalignment
bounding box of all the lines is determined by the horizontalalignment
and verticalalignment properties, but the multiline text within that
box can be

Expand Down Expand Up @@ -957,11 +961,11 @@ def set_verticalalignment(self, align):
"""
Set the vertical alignment

ACCEPTS: [ 'center' | 'top' | 'bottom' | 'baseline' ]
ACCEPTS: [ 'center' | 'top' | 'bottom' | 'baseline' | fraction text height from bottom ]
"""
legal = ('top', 'bottom', 'center', 'baseline')
if align not in legal:
raise ValueError('Vertical alignment must be one of %s' % str(legal))
if align not in legal and not is_numlike(align):
raise ValueError('Vertical alignment must be numeric or one of %s' % str(legal))

self._verticalalignment = align

Expand Down