HOWTO · Matplotlib
How to Display Greek Letters in Python Matplotlib
Display Greek letters in Matplotlib with Mathtext, Unicode code points, or direct Unicode characters.
On this page
To put Greek letters in a Matplotlib title, axis label, or annotation, use Mathtext such as r"$\alpha$", build a character from its Unicode code point with Python’s chr(), or type the Unicode character directly into a string. Mathtext is usually the simplest option for mathematical labels; direct Unicode is convenient for ordinary text, while TextPath is useful when a label must be handled as a path. (matplotlib)
Display Greek Letters in Matplotlib with Mathtext
Matplotlib’s built-in Mathtext parser understands many familiar math expressions without enabling external LaTeX rendering. Put the expression between dollar signs and use a raw Python string so backslashes reach the parser unchanged. Prefix a Greek letter name with a backslash: r"$\alpha$" renders α. The same syntax works in titles, axis labels, and annotations.
This complete example places two symbols in a plot title and labels both axes:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
ax.set_title(r"$\alpha$ and $\beta$")
ax.set_xlabel(r"$\mu$")
ax.set_ylabel(r"$\sigma$")
plt.show()
You can combine Mathtext with surrounding words by placing the expression in the same string, for example r"Mean $\mu$ and spread $\sigma$". Keep each math expression inside its own pair of dollar signs. For a literal dollar sign or more advanced notation, consult Matplotlib’s Mathtext syntax; the example here does not require text.usetex=True.
Convert Unicode Code Points with Python’s chr()
Python’s chr() takes an integer Unicode code point and returns the corresponding character. For example, chr(945) is α. The values 945 through 969 cover lowercase Greek code points, including final sigma (ς). chr() works with Unicode code points generally, not only alphabetic values. This method is useful when a symbol comes from data or a numeric configuration.
import matplotlib.pyplot as plt
alpha = chr(945)
beta = chr(946)
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
ax.set_title(f"{alpha} and {beta}")
ax.set_xlabel(alpha)
plt.show()
The returned characters can be combined with regular text or other strings just like any other Python string. chr() converts from a code point to a character; it does not convert a character into an integer. Choose a code point from a Unicode character chart when you need a symbol beyond the examples above.
Use Direct Unicode Characters in Matplotlib
For a short label, you can type a Greek character directly into a Python 3 string. This often makes the intended text easiest to read in the source. The selected Matplotlib font must contain the glyph; if a character appears as a box or is missing, choose a font that supports it.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
ax.set_title("α and β")
ax.set_xlabel("μ")
ax.set_ylabel("σ")
plt.show()
The Python 2 unicode_literals import from the __future__ module is historical compatibility context only. For current Python code, use the normal Python 3 string workflow shown above.
Create Path-Based Text Labels with TextPath
TextPath turns text into a Matplotlib path, which you can add and style as a patch. This is an advanced option for custom path-based labels or shapes; ordinary plot titles and axis labels are simpler with the methods above. Its glyph appearance depends on font availability, just as other text does.
The following example creates a path for α-beta, adds it to an axes, and lets the axes fit around the path:
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.textpath import TextPath
text_path = TextPath((0, 0), "α-beta", size=24)
patch = PathPatch(text_path, facecolor="royalblue", edgecolor="none")
fig, ax = plt.subplots()
ax.add_patch(patch)
ax.autoscale_view()
ax.set_aspect("equal")
ax.set_axis_off()
plt.show()
The TextPath coordinates define the label’s shape and starting position. PathPatch supplies its fill styling, and autoscale_view() adjusts the visible axes to include the added patch. For normal titles, labels, or annotations, prefer Mathtext or Unicode so Matplotlib handles text placement and alignment for you.