<divid="unreleased-message"> You are reading an old version of the documentation (v3.0.2). For the latest version see <ahref="https://matplotlib.org/stable/tutorials/text/text_props.html">https://matplotlib.org/stable/tutorials/text/text_props.html</a></div>
<pclass="last">Click <aclass="reference internal" href="#sphx-glr-download-tutorials-text-text-props-py"><spanclass="std std-ref">here</span></a> to download the full example code</p>
<spanid="sphx-glr-tutorials-text-text-props-py"></span><h1>Text properties and layout<aclass="headerlink" href="#text-properties-and-layout" title="Permalink to this headline">¶</a></h1>
<p>Controlling properties of text and its layout with Matplotlib.</p>
<p>The <aclass="reference internal" href="../../api/text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">matplotlib.text.Text</span></code></a> instances have a variety of
properties which can be configured via keyword arguments to the text
<td><aclass="reference internal" href="../../api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle" title="matplotlib.patches.Rectangle"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">Rectangle</span></code></a> prop dict plus key <codeclass="docutils literal notranslate"><spanclass="pre">'pad'</span></code> which is a pad in points</td>
<p>You can lay out text with the alignment arguments
<codeclass="docutils literal notranslate"><spanclass="pre">horizontalalignment</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">verticalalignment</span></code>, and
<codeclass="docutils literal notranslate"><spanclass="pre">multialignment</span></code>. <codeclass="docutils literal notranslate"><spanclass="pre">horizontalalignment</span></code> controls whether the x
positional argument for the text indicates the left, center or right
side of the text bounding box. <codeclass="docutils literal notranslate"><spanclass="pre">verticalalignment</span></code> controls whether
the y positional argument for the text indicates the bottom, center or
top side of the text bounding box. <codeclass="docutils literal notranslate"><spanclass="pre">multialignment</span></code>, for newline
separated strings only, controls whether the different lines are left,
center or right justified. Here is an example which uses the
<aclass="reference internal" href="../../api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">text()</span></code></a> command to show the various alignment
possibilities. The use of <codeclass="docutils literal notranslate"><spanclass="pre">transform=ax.transAxes</span></code> throughout the
code indicates that the coordinates are given relative to the axes
bounding box, with 0,0 being the lower left of the axes and 1,1 the
<spanclass="n">fig</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.figure.html#matplotlib.pyplot.figure" title="View documentation for matplotlib.pyplot.figure"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">figure</span></a><spanclass="p">()</span>
<spanclass="c1"># axes coordinates are 0,0 is bottom left and 1,1 is upper right</span>
<spanclass="n">p</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle" title="View documentation for matplotlib.patches.Rectangle"><spanclass="n">patches</span><spanclass="o">.</span><spanclass="n">Rectangle</span></a><spanclass="p">(</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
<td>Default font size in points. Relative font sizes
(<codeclass="docutils literal notranslate"><spanclass="pre">'large'</span></code>, <codeclass="docutils literal notranslate"><spanclass="pre">'x-small'</span></code>) are computed against
this size.</td>
</tr>
</tbody>
</table>
<p>The mapping between the family aliases (<codeclass="docutils literal notranslate"><spanclass="pre">{'cursive',</span><spanclass="pre">'fantasy',</span>
<spanclass="pre">'monospace',</span><spanclass="pre">'sans',</span><spanclass="pre">'sans</span><spanclass="pre">serif',</span><spanclass="pre">'sans-serif',</span><spanclass="pre">'serif'}</span></code>) and actual font names
<h2>Text with non-latin glyphs<aclass="headerlink" href="#text-with-non-latin-glyphs" title="Permalink to this headline">¶</a></h2>
<p>As of v2.0 the <aclass="reference internal" href="../../users/dflt_style_changes.html#default-changes-font"><spanclass="std std-ref">default font</span></a> contains
glyphs for many western alphabets, but still does not cover all of the
glyphs that may be required by mpl users. For example, DejaVu has no
coverage of Chinese, Korean, or Japanese.</p>
<p>To set the default font to be one that supports the code points you
need, prepend the font name to <codeclass="docutils literal notranslate"><spanclass="pre">'font.family'</span></code> or the desired alias
lists</p>
<divclass="highlight-default notranslate"><divclass="highlight"><pre><span></span><spanclass="n">matplotlib</span><spanclass="o">.</span><spanclass="n">rcParams</span><spanclass="p">[</span><spanclass="s1">'font.sans-serif'</span><spanclass="p">]</span><spanclass="o">=</span><spanclass="p">[</span><spanclass="s1">'Source Han Sans TW'</span><spanclass="p">,</span><spanclass="s1">'sans-serif'</span><spanclass="p">]</span>
</pre></div>
</div>
<p>or set it in your <codeclass="file docutils literal notranslate"><spanclass="pre">.matplotlibrc</span></code> file:</p>