问题
I am looking for this character: Δ
which I need for a legend item in matplotlib. Python 3.x features a str
type that contains Unicode characters, but I couldn't find any valuable information about how to do it in 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)
回答1:
Although @berna1111's comment is correct, you don't need to use LaTeX format to get a ∆ character.
In python 2, you need to specify that a string is unicode by using the u''
construct (see doc here). E.g.:
plt.plot(x,z,label=u'Δ x,y')
来源:https://stackoverflow.com/questions/40611410/how-do-i-write-a-capital-greek-delta-as-a-string-in-python-2-7