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

Skip to content

Commit b5c340a

Browse files
committed
Merge pull request #2012 from mdboom/texmanager-family-list
texmanager doesn't handle list of names for `font.family`
2 parents 7e7b532 + 7293060 commit b5c340a

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
659659
color = '%1.3f,%1.3f,%1.3f'% gc.get_rgb()[:3]
660660
fontcmd = {'sans-serif' : r'{\sffamily %s}',
661661
'monospace' : r'{\ttfamily %s}'}.get(
662-
rcParams['font.family'], r'{\rmfamily %s}')
662+
rcParams['font.family'][0], r'{\rmfamily %s}')
663663
s = fontcmd % s
664664
tex = r'\color[rgb]{%s} %s' % (color, s)
665665

lib/matplotlib/font_manager.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,9 @@ def set_family(self, family):
805805
"""
806806
Change the font family. May be either an alias (generic name
807807
is CSS parlance), such as: 'serif', 'sans-serif', 'cursive',
808-
'fantasy', or 'monospace', or a real font name.
808+
'fantasy', or 'monospace', a real font name or a list of real
809+
font names. Real font names are not supported when
810+
`text.usetex` is `True`.
809811
"""
810812
if family is None:
811813
family = rcParams['font.family']
@@ -1064,9 +1066,12 @@ def score_family(self, families, family2):
10641066
options = [x.lower() for x in options]
10651067
if family2 in options:
10661068
idx = options.index(family2)
1067-
return 0.1 * (float(idx) / len(options))
1069+
return ((0.1 * (float(idx) / len(options))) *
1070+
(float(i) / float(len(families))))
10681071
elif family1 == family2:
1069-
return 0.0
1072+
# The score should be weighted by where in the
1073+
# list the font was found.
1074+
return float(i) / float(len(families))
10701075
return 1.0
10711076

10721077
def score_style(self, style1, style2):

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,14 @@ def xkcd():
278278
# This figure will be in regular style
279279
fig2 = plt.figure()
280280
"""
281+
if rcParams['text.usetex']:
282+
raise RuntimeError(
283+
"xkcd mode is not compatible with text.usetex = True")
284+
281285
from matplotlib import patheffects
282286
context = rc_context()
283287
try:
284-
rcParams['text.usetex'] = False
285-
rcParams['font.family'] = 'Humor Sans'
288+
rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
286289
rcParams['font.size'] = 14.0
287290
rcParams['path.sketch'] = (1, 100, 2)
288291
rcParams['path.effects'] = [

lib/matplotlib/texmanager.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ def __init__(self):
166166
'available'))
167167

168168
mkdirs(self.texcache)
169-
ff = rcParams['font.family'].lower()
170-
if ff in self.font_families:
171-
self.font_family = ff
169+
ff = rcParams['font.family']
170+
if len(ff) == 1 and ff[0].lower() in self.font_families:
171+
self.font_family = ff[0].lower()
172172
else:
173-
mpl.verbose.report('The %s font family is not compatible with '
174-
'LaTeX. serif will be used by default.' % ff,
175-
'helpful')
173+
mpl.verbose.report(
174+
'font.family must be one of (%s) when text.usetex is True. '
175+
'serif will be used by default.' %
176+
', '.join(self.font_families),
177+
'helpful')
176178
self.font_family = 'serif'
177179

178180
fontconfig = [self.font_family]

matplotlibrc.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ backend : %(backend)s
101101
# 'sans-serif' (e.g., Helvetica), 'cursive' (e.g., Zapf-Chancery),
102102
# 'fantasy' (e.g., Western), and 'monospace' (e.g., Courier). Each of
103103
# these font families has a default list of font names in decreasing
104-
# order of priority associated with them.
104+
# order of priority associated with them. When text.usetex is False,
105+
# font.family may also be one or more concrete font names.
105106
#
106107
# The font.style property has three values: normal (or roman), italic
107108
# or oblique. The oblique style will be used for italic, if it is not

0 commit comments

Comments
 (0)