简体   繁体   English

如何在 python 中打印数学?

[英]How to print math in python?

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 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 ) 这可能吗? I tried the following (as in matplotlib):我尝试了以下方法(如在 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例如打印一个希腊 delta,但它不起作用(因为它不是 matplotlib 函数),它显示: $\Delta v$: delta

You can actually print the characters with no issue in Python.您实际上可以在 Python 中毫无问题地打印字符。 Just find the associated unicode characters with a Google search and copy/paste them into your print statement.只需通过 Google 搜索找到相关的 unicode 字符,然后将它们复制/粘贴到您的打印语句中。

print('Δ')
print('α')

No, it is generally not possible to do this using the print function - it just outputs plain text to standard output.不,通常不可能使用print function 执行此操作 - 它只是将纯文本输出到标准 output。 matplotlib can render math text as, for instance, a plot title, because its target is the generated image. matplotlib可以将数学文本渲染为例如 plot 标题,因为它的目标是生成的图像。

Like Kurt Kline said, you can display simple characters, but not complex expressions like a sum symbol or superscripts.正如 Kurt Kline 所说,您可以显示简单的字符,但不能显示和符号或上标之类的复杂表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM