|
1 |
| -#!/usr/bin/env python |
2 | 1 | # -*- noplot -*-
|
3 | 2 | """
|
4 | 3 | matplotlib has support for freetype fonts. Here's a little example
|
|
14 | 13 | import matplotlib
|
15 | 14 | from matplotlib.ft2font import FT2Font
|
16 | 15 | from matplotlib.font_manager import FontProperties
|
17 |
| -from pylab import figure, table, show, axis, title |
| 16 | +import matplotlib.pyplot as plt |
18 | 17 |
|
19 | 18 | import six
|
20 | 19 | from six import unichr
|
|
40 | 39 | chars = [['' for c in range(16)] for r in range(16)]
|
41 | 40 | colors = [[(0.95, 0.95, 0.95) for c in range(16)] for r in range(16)]
|
42 | 41 |
|
43 |
| -figure(figsize=(8, 4), dpi=120) |
| 42 | +plt.figure(figsize=(8, 4), dpi=120) |
44 | 43 | for ccode, glyphind in codes:
|
45 | 44 | if ccode >= 256:
|
46 | 45 | continue
|
|
49 | 48 | chars[r][c] = s
|
50 | 49 |
|
51 | 50 | lightgrn = (0.5, 0.8, 0.5)
|
52 |
| -title(fontname) |
53 |
| -tab = table(cellText=chars, |
54 |
| - rowLabels=labelr, |
55 |
| - colLabels=labelc, |
56 |
| - rowColours=[lightgrn]*16, |
57 |
| - colColours=[lightgrn]*16, |
58 |
| - cellColours=colors, |
59 |
| - cellLoc='center', |
60 |
| - loc='upper left') |
| 51 | +plt.title(fontname) |
| 52 | +tab = plt.table(cellText=chars, |
| 53 | + rowLabels=labelr, |
| 54 | + colLabels=labelc, |
| 55 | + rowColours=[lightgrn]*16, |
| 56 | + colColours=[lightgrn]*16, |
| 57 | + cellColours=colors, |
| 58 | + cellLoc='center', |
| 59 | + loc='upper left') |
61 | 60 |
|
62 | 61 | for key, cell in tab.get_celld().items():
|
63 | 62 | row, col = key
|
64 | 63 | if row > 0 and col > 0:
|
65 | 64 | cell.set_text_props(fontproperties=FontProperties(fname=fontname))
|
66 |
| -axis('off') |
67 |
| -show() |
| 65 | +plt.axis('off') |
| 66 | +plt.show() |
0 commit comments