Skip to content

Commit c6faa9a

Browse files
committed
Clean up show_fonts, permit user-input sample text
1 parent 66effde commit c6faa9a

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

proplot/styletools.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,9 +3582,10 @@ def show_cycles(*args, axwidth=1.5):
35823582
return fig
35833583

35843584

3585-
def show_fonts(*args, size=12):
3585+
def show_fonts(*args, size=12, text=None):
35863586
"""
3587-
Visualize font families.
3587+
Visualize the available sans-serif fonts. If a glyph is unavailable,
3588+
it is replaced by the "¤" dummy character.
35883589
35893590
Parameters
35903591
----------
@@ -3594,36 +3595,44 @@ def show_fonts(*args, size=12):
35943595
provided by ProPlot are shown.
35953596
size : float, optional
35963597
The font size in points.
3598+
text : str, optional
3599+
The sample text. The default sample text includes the Latin letters,
3600+
Greek letters, Arabic numerals, and some mathematical symbols.
35973601
"""
35983602
from . import subplots
35993603
if not args:
36003604
import matplotlib.font_manager as mfonts
36013605
args = sorted({
36023606
font.name for font in mfonts.fontManager.ttflist
3603-
if font.name in FONTS_SANS
3604-
or any(path in font.fname for path in _get_data_paths('fonts'))
3607+
if font.name[:1] != '.' and (
3608+
font.name in FONTS_SANS
3609+
or any(path in font.fname for path in _get_data_paths('fonts'))
3610+
)
36053611
})
36063612

36073613
# Text
3608-
math = r'(0) + {1} - [2] * <3> / 4,0 $\geq\gg$ 5.0 $\leq\ll$ ~6 ' \
3609-
r'$\times$ 7 $\equiv$ 8 $\approx$ 9 $\propto$'
3610-
greek = r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ ' \
3614+
if text is None:
3615+
text = 'the quick brown fox jumps over a lazy dog' '\n' \
3616+
'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG' '\n' \
3617+
'(0) + {1\N{DEGREE SIGN}} \N{MINUS SIGN} [2*] - <3> / 4,0 ' \
3618+
r'$\geq\gg$ 5.0 $\leq\ll$ ~6 $\times$ 7 ' \
3619+
r'$\equiv$ 8 $\approx$ 9 $\propto$' '\n' \
3620+
r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ ' \
36113621
r'$\epsilon\zeta\eta$ $\Theta\theta$ $\kappa\mu\nu$ ' \
36123622
r'$\Lambda\lambda$ $\Pi\pi$ $\xi\rho\tau\chi$ $\Sigma\sigma$ ' \
36133623
r'$\Phi\phi$ $\Psi\psi$ $\Omega\omega$ !?&#%'
3614-
letters = 'the quick brown fox jumps over a lazy dog\n' \
3615-
'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG'
36163624

36173625
# Create figure
36183626
f, axs = subplots(ncols=1, nrows=len(args), space=0,
3619-
axwidth=4.5, axheight=6.5 * size / 72)
3627+
axwidth=4.5, axheight=6.5 * size / 72,
3628+
fallback_to_cm=False)
36203629
axs.format(xloc='neither', yloc='neither',
36213630
xlocator='null', ylocator='null', alpha=0)
36223631
axs[0].format(title='Fonts demo', titlesize=size,
36233632
titleloc='l', titleweight='bold')
36243633
for i, ax in enumerate(axs):
36253634
font = args[i]
3626-
ax.text(0, 0.5, f'{font}:\n{letters}\n{math}\n{greek}',
3635+
ax.text(0, 0.5, f'{font}:\n{text}',
36273636
fontfamily=font, fontsize=size,
36283637
weight='normal', ha='left', va='center')
36293638
return f

0 commit comments

Comments
 (0)