Skip to content

Commit cc61700

Browse files
committed
Change behavior of font.* rcParams so they take effect only on to-be-created text objects
1 parent edb1526 commit cc61700

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

doc/api/api_changes.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ For new features that were added to matplotlib, please see
1515
Changes in 1.3.x
1616
================
1717

18-
* Fixed a bug in setting the position for the right/top spine with data
18+
* The `font.*` rcParams now affect only text objects created after the
19+
rcParam has been set, and will not retroactively affect already
20+
existing text objects. This brings their behavior in line with most
21+
other rcParams.
22+
23+
* Fixed a bug in setting the position for the right/top spine with data
1924
position type. Previously, it would draw the right or top spine at
2025
+1 data offset.
2126

doc/users/whats_new.rst

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ simply call `pyplot.xkcd` before creating your plot.
3333
.. plot:: mpl_examples/showcase/xkcd.py
3434

3535

36+
Changes to font rcParams
37+
------------------------
38+
The `font.*` rcParams now affect only text objects created after the
39+
rcParam has been set, and will not retroactively affect already
40+
existing text objects. This brings their behavior in line with most
41+
other rcParams.
42+
3643
``axes.xmargin`` and ``axes.ymargin`` added to rcParams
3744
-------------------------------------------------------
3845
``rcParam`` values (``axes.xmargin`` and ``axes.ymargin``) were added

lib/matplotlib/font_manager.py

+33-27
Original file line numberDiff line numberDiff line change
@@ -808,18 +808,19 @@ def set_family(self, family):
808808
'fantasy', or 'monospace', or a real font name.
809809
"""
810810
if family is None:
811-
self._family = None
812-
else:
813-
if is_string_like(family):
814-
family = [family]
815-
self._family = family
811+
family = rcParams['font.family']
812+
if is_string_like(family):
813+
family = [family]
814+
self._family = family
816815
set_name = set_family
817816

818817
def set_style(self, style):
819818
"""
820819
Set the font style. Values are: 'normal', 'italic' or
821820
'oblique'.
822821
"""
822+
if style is None:
823+
style = rcParams['font.style']
823824
if style not in ('normal', 'italic', 'oblique', None):
824825
raise ValueError("style must be normal, italic or oblique")
825826
self._slant = style
@@ -829,6 +830,8 @@ def set_variant(self, variant):
829830
"""
830831
Set the font variant. Values are: 'normal' or 'small-caps'.
831832
"""
833+
if variant is None:
834+
variant = rcParams['font.variant']
832835
if variant not in ('normal', 'small-caps', None):
833836
raise ValueError("variant must be normal or small-caps")
834837
self._variant = variant
@@ -840,14 +843,15 @@ def set_weight(self, weight):
840843
'regular', 'book', 'medium', 'roman', 'semibold', 'demibold',
841844
'demi', 'bold', 'heavy', 'extra bold', 'black'
842845
"""
843-
if weight is not None:
844-
try:
845-
weight = int(weight)
846-
if weight < 0 or weight > 1000:
847-
raise ValueError()
848-
except ValueError:
849-
if weight not in weight_dict:
850-
raise ValueError("weight is invalid")
846+
if weight is None:
847+
weight = rcParams['font.weight']
848+
try:
849+
weight = int(weight)
850+
if weight < 0 or weight > 1000:
851+
raise ValueError()
852+
except ValueError:
853+
if weight not in weight_dict:
854+
raise ValueError("weight is invalid")
851855
self._weight = weight
852856

853857
def set_stretch(self, stretch):
@@ -857,14 +861,15 @@ def set_stretch(self, stretch):
857861
'semi-expanded', 'expanded', 'extra-expanded' or
858862
'ultra-expanded', or a numeric value in the range 0-1000.
859863
"""
860-
if stretch is not None:
861-
try:
862-
stretch = int(stretch)
863-
if stretch < 0 or stretch > 1000:
864-
raise ValueError()
865-
except ValueError:
866-
if stretch not in stretch_dict:
867-
raise ValueError("stretch is invalid")
864+
if stretch is None:
865+
stretch = rcParams['font.weight']
866+
try:
867+
stretch = int(stretch)
868+
if stretch < 0 or stretch > 1000:
869+
raise ValueError()
870+
except ValueError:
871+
if stretch not in stretch_dict:
872+
raise ValueError("stretch is invalid")
868873
self._stretch = stretch
869874

870875
def set_size(self, size):
@@ -873,12 +878,13 @@ def set_size(self, size):
873878
'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'
874879
or an absolute font size, e.g., 12.
875880
"""
876-
if size is not None:
877-
try:
878-
size = float(size)
879-
except ValueError:
880-
if size is not None and size not in font_scalings:
881-
raise ValueError("size is invalid")
881+
if size is None:
882+
size = rcParams['font.size']
883+
try:
884+
size = float(size)
885+
except ValueError:
886+
if size is not None and size not in font_scalings:
887+
raise ValueError("size is invalid")
882888
self._size = size
883889

884890
def set_file(self, file):

lib/matplotlib/rcsetup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def validate_colorlist(s):
262262

263263
def validate_stringlist(s):
264264
'return a list'
265-
if type(s) is str:
265+
if type(s) in (str, unicode):
266266
return [v.strip() for v in s.split(',')]
267267
else:
268268
assert type(s) in [list, tuple]
@@ -513,7 +513,7 @@ def __call__(self, s):
513513

514514

515515
## font props
516-
'font.family': ['sans-serif', str], # used by text object
516+
'font.family': ['sans-serif', validate_stringlist], # used by text object
517517
'font.style': ['normal', str],
518518
'font.variant': ['normal', str],
519519
'font.stretch': ['normal', str],

0 commit comments

Comments
 (0)