Skip to main content
 首页 » 编程设计

python之python plot 中的一个错误

2024年12月31日7arxive

import numpy as np 
import matplotlib.pyplot as plt 
 
from mpl_toolkits.mplot3d import Axes3D 
from sklearn.linear_model import LinearRegression 
 
a = np.zeros((1000,3)) 
fig=plt.figure() 
ax=fig.gca(projection='3d') 
line1,=ax.plot(a[:,0], a[:,1], a[:,2], 'k') 
ax.set_xlabel('$x_1_t$');ax.set_ylabel('$x_1_t-tau$');ax.set_zlabel('$x_1_t-2tau$') 
plt.title('hello') 
plt.show() 

我使用 python2.x。错误信息如下。任何人都知道如何解决它?

Traceback (most recent call last): 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.py", line 83, in _draw 
    self.figure.draw(renderer) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper 
    return draw(artist, renderer, *args, **kwargs) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/figure.py", line 1475, in draw 
    renderer, self, artists, self.suppressComposite) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images 
    a.draw(renderer) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 298, in draw 
    ax.draw(renderer) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axis3d.py", line 306, in draw 
    self.label.draw(renderer) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 55, in draw_wrapper 
    return draw(artist, renderer, *args, **kwargs) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py", line 706, in draw 
    bbox, info, descent = textobj._get_layout(renderer) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/text.py", line 309, in _get_layout 
    ismath=ismath) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 237, in get_text_width_height_descent 
    self.mathtext_parser.parse(s, self.dpi, prop) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mathtext.py", line 3293, in parse 
    box = self._parser.parse(s, font_output, fontsize, dpi) 
   File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mathtext.py", line 2521, in parse 
    six.text_type(err)])) 
 ValueError:  
^ Double subscript (at char 0), (line:1, col:1) 

请您参考如下方法:

正如另一个答案所暗示的,问题是试图在轴标签中使用双下标。解决方案取决于您希望标签的外观。

如果您希望 1 和 t 都是下标,那么您可以使用:

$x_{1t}$ 

如果您希望第一个下划线是实际的下划线,那么您可以使用

$x\_1_t$