Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

texmanager doesn't handle list of names for `font.family` #2012

Merged
merged 3 commits into from

2 participants

@mdboom
Owner

No description provided.

@mdboom mdboom was assigned
@mdboom mdboom referenced this pull request from a commit
@mdboom mdboom Change behavior of `font.*` rcParams so they take effect only on to-b…
…e-created text objects
cc61700
@mdboom mdboom Fixes a number of bugs introduced by cc61700. texmanager will now sti…
…ll 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).
2ea3dcb
@mdboom
Owner

@leejjon, @paalge, @pelson: I think this addresses a number of the problems brought on by cc61700. If you wouldn't mind confirming this addresses it, I'd like to fast track this since all text.usetex on master is currently broken.

@pelson
Collaborator

Seems ok to me. My only critique is that it seems like the font system is being squeezed here to support something it wasn't originally designed for - is there an issue to raise this as a topic of a MEP for v1.4 (in my head I thought I'd seen one somewhere)?

lib/matplotlib/font_manager.py
((6 lines not shown))
elif family1 == family2:
- return 0.0
+ return 0.1 * float(i)
@pelson Collaborator
pelson added a note

This seems a bit magic to me, but I can live with it...

@mdboom Owner
mdboom added a note

True. float(i) / float(len(families)) would be less magical. I'll change it to that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/matplotlib/pyplot.py
@@ -278,11 +278,13 @@ def xkcd():
# This figure will be in regular style
fig2 = plt.figure()
"""
+ if rcParams['text.usetex']:
+ raise RuntimeError("xkcd mode is not compatible with text.usetex = True")
@pelson Collaborator
pelson added a note

Probably longer than 79 chars?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mdboom
Owner

I agree that the font system could probably use some new polish.

The font system has supported selecting fonts by a list of family names for a very long time -- it's just that it's now be exposed to the rcParam level.

The real problem here, in my opinion, is that the same parameters are being overloaded for use by the built-in font system and the LaTeX font system and they (necessarily) have very different semantics on how they handle things. This should probably be split into 3 things (somehow) -- a common interface that "does the right thing" in both contexts, and then separate things for more detailed control of each text type. I've thought for a long time that what we need is the concept of pluggable text backends so we could have the built-in matplotlib one, LaTeX, Pango, Apple and other text rendering infrastructure selectable and individually configurable -- but, yes, that's definitely a MEP-level discussion.

@mdboom mdboom merged commit b5c340a into from
@mdboom mdboom deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 15, 2013
  1. @mdboom

    Fixes a number of bugs introduced by cc61700. texmanager will now sti…

    mdboom authored
    …ll 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).
  2. @mdboom
  3. @mdboom

    Long line

    mdboom authored
This page is out of date. Refresh to see the latest.
View
2  lib/matplotlib/backends/backend_ps.py
@@ -659,7 +659,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
color = '%1.3f,%1.3f,%1.3f'% gc.get_rgb()[:3]
fontcmd = {'sans-serif' : r'{\sffamily %s}',
'monospace' : r'{\ttfamily %s}'}.get(
- rcParams['font.family'], r'{\rmfamily %s}')
+ rcParams['font.family'][0], r'{\rmfamily %s}')
s = fontcmd % s
tex = r'\color[rgb]{%s} %s' % (color, s)
View
11 lib/matplotlib/font_manager.py
@@ -805,7 +805,9 @@ def set_family(self, family):
"""
Change the font family. May be either an alias (generic name
is CSS parlance), such as: 'serif', 'sans-serif', 'cursive',
- 'fantasy', or 'monospace', or a real font name.
+ 'fantasy', or 'monospace', a real font name or a list of real
+ font names. Real font names are not supported when
+ `text.usetex` is `True`.
"""
if family is None:
family = rcParams['font.family']
@@ -1064,9 +1066,12 @@ def score_family(self, families, family2):
options = [x.lower() for x in options]
if family2 in options:
idx = options.index(family2)
- return 0.1 * (float(idx) / len(options))
+ return ((0.1 * (float(idx) / len(options))) *
+ (float(i) / float(len(families))))
elif family1 == family2:
- return 0.0
+ # The score should be weighted by where in the
+ # list the font was found.
+ return float(i) / float(len(families))
return 1.0
def score_style(self, style1, style2):
View
7 lib/matplotlib/pyplot.py
@@ -278,11 +278,14 @@ def xkcd():
# This figure will be in regular style
fig2 = plt.figure()
"""
+ if rcParams['text.usetex']:
+ raise RuntimeError(
+ "xkcd mode is not compatible with text.usetex = True")
+
from matplotlib import patheffects
context = rc_context()
try:
- rcParams['text.usetex'] = False
- rcParams['font.family'] = 'Humor Sans'
+ rcParams['font.family'] = ['Humor Sans', 'Comic Sans MS']
rcParams['font.size'] = 14.0
rcParams['path.sketch'] = (1, 100, 2)
rcParams['path.effects'] = [
View
14 lib/matplotlib/texmanager.py
@@ -166,13 +166,15 @@ def __init__(self):
'available'))
mkdirs(self.texcache)
- ff = rcParams['font.family'].lower()
- if ff in self.font_families:
- self.font_family = ff
+ ff = rcParams['font.family']
+ if len(ff) == 1 and ff[0].lower() in self.font_families:
+ self.font_family = ff[0].lower()
else:
- mpl.verbose.report('The %s font family is not compatible with '
- 'LaTeX. serif will be used by default.' % ff,
- 'helpful')
+ mpl.verbose.report(
+ 'font.family must be one of (%s) when text.usetex is True. '
+ 'serif will be used by default.' %
+ ', '.join(self.font_families),
+ 'helpful')
self.font_family = 'serif'
fontconfig = [self.font_family]
View
3  matplotlibrc.template
@@ -101,7 +101,8 @@ backend : %(backend)s
# 'sans-serif' (e.g., Helvetica), 'cursive' (e.g., Zapf-Chancery),
# 'fantasy' (e.g., Western), and 'monospace' (e.g., Courier). Each of
# these font families has a default list of font names in decreasing
-# order of priority associated with them.
+# order of priority associated with them. When text.usetex is False,
+# font.family may also be one or more concrete font names.
#
# The font.style property has three values: normal (or roman), italic
# or oblique. The oblique style will be used for italic, if it is not
Something went wrong with that request. Please try again.