How to print math symbols

Question:

I would like to print math in python with print(), as it is possible to do in plot’s label with matplotlib (see this link for all the math you can write with matplotlib https://matplotlib.org/tutorials/text/mathtext.html )
Is that even possible ?
I tried the following (as in matplotlib):

print(r'$Delta v$:', delta)

to print a greek delta for example, but it doesn’t work (as it’s not a matplotlib function), it shows : $Delta v$: delta

Asked By: Apinorr

||

Answers:

You can actually print the characters with no issue in Python. Just find the associated unicode characters with a Google search and copy/paste them into your print statement.

print('Δ')
print('α')
Answered By: Kurt Kline

No, it is generally not possible to do this using the print function – it just outputs plain text to standard output. matplotlib can render math text as, for instance, a plot title, because its target is the generated image.

Like Kurt Kline said, you can display simple characters, but not complex expressions like a sum symbol or superscripts.

Answered By: JakuJ
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.