Skip to content
Browse files

Change behavior of `font.*` rcParams so they take effect only on to-b…

…e-created text objects
  • Loading branch information...
1 parent edb1526 commit cc617006f7f0a18396cecf4a9f1e222f1ee5204e @mdboom committed May 14, 2013
Showing with 48 additions and 30 deletions.
  1. +6 −1 doc/api/api_changes.rst
  2. +7 −0 doc/users/whats_new.rst
  3. +33 −27 lib/matplotlib/font_manager.py
  4. +2 −2 lib/matplotlib/rcsetup.py
View
7 doc/api/api_changes.rst
@@ -15,7 +15,12 @@ For new features that were added to matplotlib, please see
Changes in 1.3.x
================
-* Fixed a bug in setting the position for the right/top spine with data
+* The `font.*` rcParams now affect only text objects created after the
+ rcParam has been set, and will not retroactively affect already
+ existing text objects. This brings their behavior in line with most
+ other rcParams.
+
+* Fixed a bug in setting the position for the right/top spine with data
position type. Previously, it would draw the right or top spine at
+1 data offset.
View
7 doc/users/whats_new.rst
@@ -33,6 +33,13 @@ simply call `pyplot.xkcd` before creating your plot.
.. plot:: mpl_examples/showcase/xkcd.py
+Changes to font rcParams
+------------------------
+The `font.*` rcParams now affect only text objects created after the
+rcParam has been set, and will not retroactively affect already
+existing text objects. This brings their behavior in line with most
+other rcParams.
+
``axes.xmargin`` and ``axes.ymargin`` added to rcParams
-------------------------------------------------------
``rcParam`` values (``axes.xmargin`` and ``axes.ymargin``) were added
View
60 lib/matplotlib/font_manager.py
@@ -808,18 +808,19 @@ def set_family(self, family):
'fantasy', or 'monospace', or a real font name.
"""
if family is None:
- self._family = None
- else:
- if is_string_like(family):
- family = [family]
- self._family = family
+ family = rcParams['font.family']
+ if is_string_like(family):
+ family = [family]
+ self._family = family
set_name = set_family
def set_style(self, style):
"""
Set the font style. Values are: 'normal', 'italic' or
'oblique'.
"""
+ if style is None:
+ style = rcParams['font.style']
if style not in ('normal', 'italic', 'oblique', None):
raise ValueError("style must be normal, italic or oblique")
self._slant = style
@@ -829,6 +830,8 @@ def set_variant(self, variant):
"""
Set the font variant. Values are: 'normal' or 'small-caps'.
"""
+ if variant is None:
+ variant = rcParams['font.variant']
if variant not in ('normal', 'small-caps', None):
raise ValueError("variant must be normal or small-caps")
self._variant = variant
@@ -840,14 +843,15 @@ def set_weight(self, weight):
'regular', 'book', 'medium', 'roman', 'semibold', 'demibold',
'demi', 'bold', 'heavy', 'extra bold', 'black'
"""
- if weight is not None:
- try:
- weight = int(weight)
- if weight < 0 or weight > 1000:
- raise ValueError()
- except ValueError:
- if weight not in weight_dict:
- raise ValueError("weight is invalid")
+ if weight is None:
+ weight = rcParams['font.weight']
+ try:
+ weight = int(weight)
+ if weight < 0 or weight > 1000:
+ raise ValueError()
+ except ValueError:
+ if weight not in weight_dict:
+ raise ValueError("weight is invalid")
self._weight = weight
def set_stretch(self, stretch):
@@ -857,14 +861,15 @@ def set_stretch(self, stretch):
'semi-expanded', 'expanded', 'extra-expanded' or
'ultra-expanded', or a numeric value in the range 0-1000.
"""
- if stretch is not None:
- try:
- stretch = int(stretch)
- if stretch < 0 or stretch > 1000:
- raise ValueError()
- except ValueError:
- if stretch not in stretch_dict:
- raise ValueError("stretch is invalid")
+ if stretch is None:
+ stretch = rcParams['font.weight']
+ try:
+ stretch = int(stretch)
+ if stretch < 0 or stretch > 1000:
+ raise ValueError()
+ except ValueError:
+ if stretch not in stretch_dict:
+ raise ValueError("stretch is invalid")
self._stretch = stretch
def set_size(self, size):
@@ -873,12 +878,13 @@ def set_size(self, size):
'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
or an absolute font size, e.g., 12.
"""
- if size is not None:
- try:
- size = float(size)
- except ValueError:
- if size is not None and size not in font_scalings:
- raise ValueError("size is invalid")
+ if size is None:
+ size = rcParams['font.size']
+ try:
+ size = float(size)
+ except ValueError:
+ if size is not None and size not in font_scalings:
+ raise ValueError("size is invalid")
self._size = size
def set_file(self, file):
View
4 lib/matplotlib/rcsetup.py
@@ -262,7 +262,7 @@ def validate_colorlist(s):
def validate_stringlist(s):
'return a list'
- if type(s) is str:
+ if type(s) in (str, unicode):
return [v.strip() for v in s.split(',')]
else:
assert type(s) in [list, tuple]
@@ -513,7 +513,7 @@ def __call__(self, s):
## font props
- 'font.family': ['sans-serif', str], # used by text object
+ 'font.family': ['sans-serif', validate_stringlist], # used by text object
'font.style': ['normal', str],
'font.variant': ['normal', str],
'font.stretch': ['normal', str],

0 comments on commit cc61700

Please sign in to comment.
Something went wrong with that request. Please try again.