|
1 | 1 | .. _text-properties: |
2 | 2 |
|
3 | | -Text properties and layout |
4 | | -========================== |
| 3 | +============================ |
| 4 | + Text properties and layout |
| 5 | +============================ |
5 | 6 |
|
6 | 7 | The :class:`matplotlib.text.Text` instances have a variety of |
7 | 8 | properties which can be configured via keyword arguments to the text |
@@ -59,3 +60,93 @@ upper right. |
59 | 60 |
|
60 | 61 | .. plot:: pyplots/text_layout.py |
61 | 62 | :include-source: |
| 63 | + |
| 64 | + |
| 65 | +============== |
| 66 | + Default Font |
| 67 | +============== |
| 68 | + |
| 69 | +The base default font is controlled by a set of rcParams |
| 70 | + |
| 71 | + |
| 72 | ++---------------------+----------------------------------------------------+ |
| 73 | +| ``'font.family'`` | List of either names of font or ``{'cursive', | |
| 74 | +| | 'fantasy', 'monospace', 'sans', 'sans serif', | |
| 75 | +| | 'sans-serif', 'serif'}``. | |
| 76 | +| | | |
| 77 | ++---------------------+----------------------------------------------------+ |
| 78 | +| ``'font.style'`` | The default style, ex ``'normal'``, | |
| 79 | +| | ``'italic'``. | |
| 80 | +| | | |
| 81 | ++---------------------+----------------------------------------------------+ |
| 82 | +| ``'font.variant'`` | Default variant, ex ``'normal'``, ``'small-caps'`` | |
| 83 | +| | (untested) | |
| 84 | ++---------------------+----------------------------------------------------+ |
| 85 | +| ``'font.stretch'`` | Default stretch, ex ``'normal'``, ``'condensed'`` | |
| 86 | +| | (incomplete) | |
| 87 | +| | | |
| 88 | ++---------------------+----------------------------------------------------+ |
| 89 | +| ``'font.weight'`` | Default weight. Either string or integer | |
| 90 | +| | | |
| 91 | +| | | |
| 92 | ++---------------------+----------------------------------------------------+ |
| 93 | +| ``'font.size'`` | Default font size in points. Relative font sizes | |
| 94 | +| | (``'large'``, ``'x-small'``) are computed against | |
| 95 | +| | this size. | |
| 96 | ++---------------------+----------------------------------------------------+ |
| 97 | + |
| 98 | +The mapping between the family aliases (``{'cursive', 'fantasy', |
| 99 | +'monospace', 'sans', 'sans serif', 'sans-serif', 'serif'}``) and actual font names |
| 100 | +is controlled by the following rcParms |
| 101 | + |
| 102 | + |
| 103 | ++----------------------------+----------------------------------------------------+ |
| 104 | +| ``'serif'`` | ``'font.serif'`` | |
| 105 | ++----------------------------+----------------------------------------------------+ |
| 106 | +| ``'monospace'`` | ``'font.monospace'`` | |
| 107 | ++----------------------------+----------------------------------------------------+ |
| 108 | +| ``'fantasy'`` | ``'font.fantasy'`` | |
| 109 | ++----------------------------+----------------------------------------------------+ |
| 110 | +|``'cursive'`` | ``'font.cursive'`` | |
| 111 | ++----------------------------+----------------------------------------------------+ |
| 112 | +| ``{'sans', 'sans serif', | ``'font.sans-serif'`` | |
| 113 | +| 'sans-serif'}`` | | |
| 114 | +| | | |
| 115 | ++----------------------------+----------------------------------------------------+ |
| 116 | + |
| 117 | + |
| 118 | +which are lists of font names. |
| 119 | + |
| 120 | +Set default font with non-latin code points |
| 121 | +=========================================== |
| 122 | + |
| 123 | +From v2.0 forward the :ref:`default font <default_changes_font>` contains |
| 124 | +code points for many western languages, but does not cover eastern |
| 125 | +scripts (ex Chinese, Korean, or Japanese). If you use unicode points |
| 126 | +not covered by the default font you will see the dreaded 'code point |
| 127 | +not found' place holder (typically an empty rectangle). To set the |
| 128 | +default font to be one that support the code points you need prepend |
| 129 | +the font name to ``'font.family'`` or the desired alias lists :: |
| 130 | + |
| 131 | + matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif'] |
| 132 | + |
| 133 | +or set it in your :file:`.matplotlibrc` file:: |
| 134 | + |
| 135 | + font.sans-serif: Source Han Sans TW, Ariel, sans-serif |
| 136 | + |
| 137 | + |
| 138 | +On linux `fc-list <http://linux.die.net/man/1/fc-list>`__ can be a |
| 139 | +useful tool to discover the font name for example :: |
| 140 | + |
| 141 | + $ fc-list :lang=zh family |
| 142 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW ExtraLight,Source Han Sans TW ExtraLight |
| 143 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Regular,Source Han Sans TW Regular |
| 144 | + Droid Sans Fallback |
| 145 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Bold,Source Han Sans TW Bold |
| 146 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Medium,Source Han Sans TW Medium |
| 147 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Normal,Source Han Sans TW Normal |
| 148 | + Fixed |
| 149 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Heavy,Source Han Sans TW Heavy |
| 150 | + Source Han Sans TW,思源黑體 TW,思源黑體 TW Light,Source Han Sans TW Light |
| 151 | + |
| 152 | +lists all of the fonts that support Chinese. |
0 commit comments