Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib和unicode字符_Python_Python 3.x_Matplotlib_Unicode - Fatal编程技术网

Python matplotlib和unicode字符

Python matplotlib和unicode字符,python,python-3.x,matplotlib,unicode,Python,Python 3.x,Matplotlib,Unicode,我在上查看了tex\u unicode\u demo.py。他们未能在绘图上正确插入unicode\u00B0。一个人是如何做到这一点的 from __future__ import unicode_literals import numpy as np import matplotlib matplotlib.rcParams['text.usetex'] = True matplotlib.rcParams['text.latex.unicode'] = True import matplo

我在上查看了
tex\u unicode\u demo.py
。他们未能在绘图上正确插入unicode
\u00B0
。一个人是如何做到这一点的

from __future__ import unicode_literals
import numpy as np
import matplotlib
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['text.latex.unicode'] = True
import matplotlib.pyplot as plt

plt.figure(1, figsize=(6, 4))
ax = plt.axes([0.1, 0.1, 0.8, 0.7])
t = np.arange(0.0, 1.0 + 0.01, 0.01)
s = np.cos(2*2*np.pi*t) + 2
plt.plot(t, s)

plt.xlabel(r'\textbf{time (s)}')
plt.ylabel(r'\textit{Velocity (\u00B0/sec)}', fontsize=16)
plt.title(r"\TeX\ is Number \
          $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
          fontsize=16, color='r')
plt.grid(True)

这是因为您使用的是原始字符串
r'…'
。尝试使用普通字符串(或至少格式化字符串或将其分成两部分)

注意中间线中的新两个代码> <代码>。< /P> 为了更清楚,您可以格式化字符串

plt.ylabel(r'\textit{Velocity (%s/sec)}' % '\u00B0', fontsize=16)

这对于连接字符串可能很有意义:
plt.ylabel(r'\textit{Velocity (%s/sec)}' % '\u00B0', fontsize=16)