@@ -803,7 +803,9 @@ def show_colors(*, nhues=17, minsat=10, unknown='User', include=None, ignore=Non
803803 return fig , axs
804804
805805
806- def show_fonts (* args , family = None , text = None , math = False , ** kwargs ):
806+ def show_fonts (
807+ * args , family = None , user = None , text = None , math = False , fallback = False , ** kwargs
808+ ):
807809 """
808810 Generate a table of fonts. If a glyph for a particular font is unavailable,
809811 it is replaced with the "¤" dummy character.
@@ -818,17 +820,25 @@ def show_fonts(*args, family=None, text=None, math=False, **kwargs):
818820 :rcraw:`font.sans-serif` fonts are shown.
819821 family \
820822 : {'tex-gyre', 'sans-serif', 'serif', 'monospace', 'cursive', 'fantasy'}, optional
821- If provided, the *available* fonts in the corresponding families are shown.
822- The fonts belonging to these families are listed under the :rcraw:`font.serif`,
823+ The family from which *available* fonts are shown. Default is ``'sans-serif'``
824+ if no arguments were provided. Otherwise the default is to not show family
825+ fonts. The fonts belonging to each family are listed under :rcraw:`font.serif`,
823826 :rcraw:`font.sans-serif`, :rcraw:`font.monospace`, :rcraw:`font.cursive`, and
824- :rcraw:`font.fantasy` settings. The special family ``'tex-gyre'`` includes
825- the `TeX Gyre <http://www.gust.org.pl/projects/e-foundry/tex-gyre>`__ fonts.
827+ :rcraw:`font.fantasy`. The special family ``'tex-gyre'`` includes the
828+ `TeX Gyre <http://www.gust.org.pl/projects/e-foundry/tex-gyre>`__ fonts.
829+ user : bool, optional
830+ Whether to include fonts in `~proplot.config.Configurator.user_folder` and
831+ `~proplot.config.Configurator.local_folders` at the top of the table. Default
832+ is ``True`` if called without any arguments and ``False`` otherwise.
826833 text : str, optional
827834 The sample text shown for each font. If not passed then default math or
828835 non-math sample text is used.
829836 math : bool, default: False
830837 Whether the default sample text should show non-math Latin characters or
831838 or math equations and Greek letters.
839+ fallback : bool, default: False
840+ Whether to use the fallback font :rcraw:`mathtext.fallback` for unavailable
841+ characters. If ``False`` the dummy glyph "¤" is shown for missing characters.
832842 **kwargs
833843 Additional font properties passed to `~matplotlib.font_manager.FontProperties`.
834844 Default size is ``12`` and default weight, style, and strength are ``'normal'``.
@@ -875,8 +885,9 @@ def show_fonts(*args, family=None, text=None, math=False, **kwargs):
875885 warnings ._warn_proplot (f'Input font name { opts [:1 ]!r} not found. Skipping.' )
876886
877887 # Add user and family FontProperties.
878- if not args and family is None :
879- family = 'sans-serif'
888+ user = _not_none (user , not args and family is None )
889+ family = _not_none (family , None if args else 'sans-serif' )
890+ if user :
880891 paths = _get_data_folders ('fonts' , default = False )
881892 for font in all_fonts : # fonts sorted by unique name
882893 if os .path .dirname (font .fname ) in paths :
@@ -894,33 +905,36 @@ def show_fonts(*args, family=None, text=None, math=False, **kwargs):
894905 props .append (mfonts .FontProperties (name , ** kwargs ))
895906
896907 # The default sample text
908+ linespacing = 0.8 if text is None and math else 1.2
897909 if text is None :
898910 if not math :
899911 text = (
900- 'the quick brown fox jumps over a lazy dog . , + -'
912+ 'the quick brown fox jumps over a lazy dog 01234 ; . , + - * ^ () || '
901913 '\n '
902- 'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG ! ? & # %'
914+ 'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG 56789 : ! ? & # % $ [] {} '
903915 )
904916 else :
905917 text = (
918+ '\n '
906919 r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ '
907920 r'$\epsilon\zeta\eta$ $\Theta\theta$ $\kappa\mu\nu$ '
908921 r'$\Lambda\lambda$ $\Pi\pi$ $\xi\rho\tau\chi$ $\Sigma\sigma$ '
909922 r'$\Phi\phi$ $\Psi\psi$ $\Omega\omega$ '
910- r'$\ll { }^k \gg [ ]_l \propto ( )^m \cdot \ left<\right>_n$'
923+ r'$\{ \; \}^i$ $[ \; ]_j$ $( \; )^k$ $\ left< \right>_n$'
911924 '\n '
912925 r'$0^a + 1_b - 2^c \times 3_d = '
913926 r'4.0^e \equiv 5.0_f \approx 6.0^g \sim 7_h \leq 8^i \geq 9_j'
914- r'\sum X \ll \int Y \gg \oint Z \propto \prod Q$ '
915- ' \n '
927+ r'\ll \prod \, P \gg \sum \, Q \, '
928+ r'\int \, Y \mathrm{d}y \propto \oint \;\, Z \mathrm{d}z$ '
916929 )
917930
918931 # Settings for rendering math text
919932 ctx = {'mathtext.fontset' : 'custom' }
920- if _version_mpl < '3.4' :
921- ctx ['mathtext.fallback_to_cm' ] = False
922- else :
923- ctx ['mathtext.fallback' ] = None
933+ if not fallback :
934+ if _version_mpl < '3.4' :
935+ ctx ['mathtext.fallback_to_cm' ] = False
936+ else :
937+ ctx ['mathtext.fallback' ] = None
924938 if 'size' not in kwargs :
925939 for prop in props :
926940 if prop .get_size () == rc ['font.size' ]:
@@ -939,6 +953,7 @@ def show_fonts(*args, family=None, text=None, math=False, **kwargs):
939953 for ax , prop in zip (axs , props ):
940954 name = prop .get_family ()[0 ]
941955 ax .text (
942- 0 , 0.5 , f'{ name } :\n { text } ' , ha = 'left' , va = 'center' , fontproperties = prop
956+ 0 , 0.5 , f'{ name } :\n { text } ' , ha = 'left' , va = 'center' ,
957+ linespacing = linespacing , fontproperties = prop
943958 )
944959 return fig , axs
0 commit comments