如何在 Python 2.7 中将大写希腊语 "delta" 写成字符串?
How do I write a capital Greek "delta" as a string in Python 2.7?
我正在寻找这个字符:Δ
我需要它作为 matplotlib 中的图例项。 Python 3.x 具有包含 Unicode 字符的 str
类型,但我在 Python 2.7.
中找不到有关如何执行此操作的任何有价值的信息
x = range(10)
y = [5] * 10
z = [y[i] - x[i] for i in xrange(10)]
plt.plot(x,z,label='Δ x,y')
plt.legend()
plt.show()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position
0: ordinal not in range(128)
虽然@berna1111 的评论是正确的,但您不需要使用 LaTeX 格式来获得 ∆ 字符。
在 python 2 中,您需要使用 u''
构造 (see doc here) 指定字符串是 unicode。例如:
plt.plot(x,z,label=u'Δ x,y')
我正在寻找这个字符:Δ
我需要它作为 matplotlib 中的图例项。 Python 3.x 具有包含 Unicode 字符的 str
类型,但我在 Python 2.7.
x = range(10)
y = [5] * 10
z = [y[i] - x[i] for i in xrange(10)]
plt.plot(x,z,label='Δ x,y')
plt.legend()
plt.show()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 0: ordinal not in range(128)
虽然@berna1111 的评论是正确的,但您不需要使用 LaTeX 格式来获得 ∆ 字符。
在 python 2 中,您需要使用 u''
构造 (see doc here) 指定字符串是 unicode。例如:
plt.plot(x,z,label=u'Δ x,y')