How to use unicode symbols in matplotlib?

Matplotlib supports Unicode symbols, allowing you to display special characters, mathematical symbols, and international text in your plots. You can use Unicode characters directly or through their escape codes.

Basic Unicode Symbol Usage

The simplest way is to use the Unicode escape sequence \u followed by the 4-digit hex code ?

import matplotlib.pyplot as plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

# Unicode symbol - Greek Delta (?)
plt.text(0.5, 0.5, s=u"\u0394", fontsize=50, ha='center', va='center')

# Display the plot
plt.show()

This displays the Greek letter Delta (?) in the center of the plot.

Multiple Unicode Symbols

You can combine multiple Unicode symbols in a single text string ?

import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [8.00, 4.00]
plt.rcParams["figure.autolayout"] = True

# Multiple Unicode symbols
symbols = [
    ("\u0394", "Delta"),      # ?
    ("\u03B1", "Alpha"),      # ?  
    ("\u03B2", "Beta"),       # ?
    ("\u2734", "Star"),       # ?
    ("\u2665", "Heart")       # ?
]

for i, (symbol, name) in enumerate(symbols):
    plt.text(0.1 + i*0.15, 0.6, symbol, fontsize=30, ha='center')
    plt.text(0.1 + i*0.15, 0.4, name, fontsize=12, ha='center')

plt.xlim(0, 1)
plt.ylim(0, 1)
plt.title("Unicode Symbols in Matplotlib")
plt.show()

Mathematical and Scientific Symbols

Common Unicode symbols for mathematical and scientific notation ?

import matplotlib.pyplot as plt

plt.figure(figsize=(10, 6))

# Mathematical symbols with their descriptions
math_symbols = [
    ("\u221E", "Infinity: ?"),
    ("\u03C0", "Pi: ?"),
    ("\u03B8", "Theta: ?"),
    ("\u00B1", "Plus-minus: ±"),
    ("\u2208", "Element of: ?"),
    ("\u2211", "Summation: ?")
]

for i, (symbol, desc) in enumerate(math_symbols):
    y_pos = 0.9 - i * 0.12
    plt.text(0.1, y_pos, symbol, fontsize=20, color='blue')
    plt.text(0.2, y_pos, desc, fontsize=14, va='center')

plt.xlim(0, 1)
plt.ylim(0, 1)
plt.title("Mathematical Unicode Symbols")
plt.axis('off')
plt.show()

Using Unicode in Plot Labels

Unicode symbols work in axis labels, titles, and legends ?

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)

plt.figure(figsize=(8, 5))
plt.plot(x, y, label='sin(?)')

plt.xlabel('Angle ? (radians)')
plt.ylabel('Amplitude ± 1')
plt.title('Sine Wave: y = sin(?) where ? ? [0, 2?]')
plt.legend()
plt.grid(True, alpha=0.3)
plt.show()

Common Unicode Codes

Symbol Unicode Code Description
? \u03B1 Greek alpha
? \u03B2 Greek beta
? \u03C0 Greek pi
? \u0394 Greek delta
? \u221E Infinity
± \u00B1 Plus-minus

Conclusion

Use Unicode escape sequences like \u0394 to display special symbols in matplotlib. This works in text, labels, titles, and legends. Ensure proper font support for complex symbols.

Updated on: 2026-03-26T14:59:03+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements