Skip to content

Commit 2ea3dcb

Browse files
committed
Fixes a number of bugs introduced by cc61700. texmanager will now still pass when font.family is a list of strings (though there's no sane way for LaTeX to deal with that, but that's nothing new).
1 parent d5b078b commit 2ea3dcb

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

lib/matplotlib/backends/backend_ps.py

+1-1
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

+5-3
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,9 @@ 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)) + float(i))
10681070
elif family1 == family2:
1069-
return 0.0
1071+
return 0.1 * float(i)
10701072
return 1.0
10711073

10721074
def score_style(self, style1, style2):

lib/matplotlib/pyplot.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,13 @@ def xkcd():
278278
# This figure will be in regular style
279279
fig2 = plt.figure()
280280
"""
281+
if rcParams['text.usetex']:
282+
raise RuntimeError("xkcd mode is not compatible with text.usetex = True")
283+
281284
from matplotlib import patheffects
282285
context = rc_context()
283286
try:
284-
rcParams['text.usetex'] = False
285-
rcParams['font.family'] = 'Humor Sans'
287+
rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
286288
rcParams['font.size'] = 14.0
287289
rcParams['path.sketch'] = (1, 100, 2)
288290
rcParams['path.effects'] = [

lib/matplotlib/texmanager.py

+8-6
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

+2-1
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)