@@ -26,7 +26,6 @@ def get_ipython():
2626__all__ = [
2727 'rc' , 'rc_configurator' , 'ipython_autosave' ,
2828 'ipython_autoreload' , 'ipython_matplotlib' ,
29- 'use_font' ,
3029]
3130
3231# Initialize
@@ -48,6 +47,9 @@ def get_ipython():
4847 'facecolor' : (
4948 'axes.facecolor' , 'geoaxes.facecolor'
5049 ),
50+ 'fontname' : (
51+ 'font.family' ,
52+ ),
5153 # change the 'color' of an axes
5254 'color' : (
5355 'axes.edgecolor' , 'geoaxes.edgecolor' , 'axes.labelcolor' ,
@@ -291,16 +293,16 @@ def _set_cycler(name):
291293
292294
293295def _get_config_paths ():
294- """Returns configuration file paths."""
296+ """Return configuration file paths in reverse order of precedence ."""
295297 # Get paths
296298 idir = os .getcwd ()
297299 paths = []
298300 while idir : # not empty string
299301 ipath = os .path .join (idir , '.proplotrc' )
300302 if os .path .exists (ipath ):
301303 paths .append (ipath )
302- ndir , _ = os .path .split (idir )
303- if ndir == idir :
304+ ndir = os .path .dirname (idir )
305+ if ndir == idir : # root
304306 break
305307 idir = ndir
306308 paths = paths [::- 1 ] # sort from decreasing to increasing importantce
@@ -398,6 +400,63 @@ def __init__(self):
398400 # https://stackoverflow.com/a/48322150/4970632
399401 plt .style .use ('default' )
400402
403+ # Prefer more widely used fonts
404+ # NOTE: Without 'mathtext.fontset' = 'custom', 'fallback_to_cm' is
405+ # always carried out! The default 'mathtext.fontset' = 'dejavusans'
406+ # creates a DejaVuFonts class which is evidently a misnomer, *always*
407+ # falls back to CM and tries to use *active* font rather than DejaVu.
408+ # NOTE: This will be put in rcParamsDefaults dictionary when #50
409+ # is merged! For now do not add to .proplotrc.
410+ import matplotlib .mathtext as _ # noqa
411+ import logging
412+ logger = logging .getLogger ('matplotlib.mathtext' )
413+ logger .setLevel (logging .ERROR ) # suppress warnings!
414+ rcParams ['mathtext.fontset' ] = 'custom'
415+ rcParams ['mathtext.default' ] = 'regular'
416+ rcParams ['text.usetex' ] = False
417+ rcParams ['font.serif' ] = (
418+ 'New Century Schoolbook' ,
419+ 'Century Schoolbook L' ,
420+ 'Utopia' ,
421+ 'ITC Bookman' ,
422+ 'Bookman' ,
423+ 'Nimbus Roman No9 L' ,
424+ 'Times New Roman' ,
425+ 'Times' ,
426+ 'Palatino' ,
427+ 'Charter'
428+ 'Computer Modern Roman' ,
429+ 'DejaVu Serif' ,
430+ 'Bitstream Vera Serif' ,
431+ 'serif' ,
432+ )
433+ rcParams ['font.sans-serif' ] = (
434+ 'Helvetica' ,
435+ 'Arial' ,
436+ 'Lucida Grande' ,
437+ 'Verdana' ,
438+ 'Geneva' ,
439+ 'Lucid' ,
440+ 'Avant Garde' ,
441+ 'TeX Gyre Sans' ,
442+ 'DejaVu Sans' ,
443+ 'Bitstream Vera Sans' ,
444+ 'Computer Modern Sans Serif' ,
445+ 'sans-serif'
446+ )
447+ rcParams ['font.monospace' ] = (
448+ 'Andale Mono' ,
449+ 'Nimbus Mono L' ,
450+ 'Courier New' ,
451+ 'Courier' ,
452+ 'Fixed' ,
453+ 'Terminal' ,
454+ 'Computer Modern Typewriter' ,
455+ 'DejaVu Sans Mono' ,
456+ 'Bitstream Vera Sans Mono' ,
457+ 'monospace'
458+ )
459+
401460 # Load the defaults from file
402461 for i , file in enumerate (_get_config_paths ()):
403462 # Load
@@ -531,8 +590,6 @@ def __setitem__(self, key, value):
531590 ipython_autosave (value )
532591 if key == 'autoreload' :
533592 ipython_autoreload (value )
534- if key == 'fontname' :
535- use_font (value )
536593 if key == 'rgbcycle' : # if must re-apply cycler afterward
537594 cache [key ] = value
538595 rcParamsShort [key ] = value
@@ -1000,34 +1057,6 @@ def ipython_autosave(autosave=None):
10001057 pass
10011058
10021059
1003- def use_font (font = None ):
1004- """
1005- Set the default font and ensure that the font used for TeX-style math
1006- is the same as the regular font by applying
1007- ``rcParams['mathtext.default'] = 'regular'``.
1008-
1009- Parameters
1010- ----------
1011- font : str, optional
1012- The font name. Default is :rc:`fontname`. If ``'auto'``, ProPlot
1013- tries to use (in order of priority) ``'Helvetica Neue'``,
1014- ``'Helvetica'``, ``'Arial'``, or ``'DejaVu Sans'``.
1015- """
1016- font = font or rcParamsShort ['fontname' ]
1017- if font == 'auto' :
1018- import matplotlib .font_manager as mfonts
1019- font = 'DejaVu Sans'
1020- fonts = sorted ({font .name for font in mfonts .fontManager .ttflist })
1021- for nicefont in (
1022- 'Helvetica Neue' , 'Helvetica' , 'Arial' , 'DejaVu Sans' ,
1023- ):
1024- if nicefont in fonts :
1025- font = nicefont
1026- break
1027- rcParams ['font.family' ] = font
1028- rcParams ['mathtext.default' ] = 'regular'
1029-
1030-
10311060#: Instance of `rc_configurator`. This is used to change global settings.
10321061#: See :ref:`Configuring proplot` for details.
10331062rc = rc_configurator ()
@@ -1036,4 +1065,3 @@ def use_font(font=None):
10361065ipython_matplotlib ()
10371066ipython_autoreload ()
10381067ipython_autosave ()
1039- use_font ()
0 commit comments