Unknown symbol: \gama, found ‘\‘ (at char 0), (line:1, col:1)

def svmsubplot(i,title,svmmodel,grid_test,x1,x2,cm_light,cm_dark,x1_min,x1_max,x2_min,x2_max):
    plt.subplot(1,3,i+1)
    grid_hat=svmmodel.predict(grid_test)
    grid_hat=grid_hat.reshape(x1.shape)
    plt.pcolormesh(x1,x2,grid_hat,cmap=cm_light,alpha=0.8)
    plt.scatter(x[0],x[1],c=y,edgecolors='k',s=40,cmap=cm_dark)
    plt.xlim(x1_min,x1_max)
    plt.ylim(x2_min,x2_max)
    plt.title(title,fontsize=8)

使用matplotlib画图报错如下:

ParseFatalException                       Traceback (most recent call last)
d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, fonts_object, fontsize, dpi)
   2608         try:
-> 2609             result = self._expression.parseString(s)
   2610         except ParseBaseException as err:

d:\ProgramData\Anaconda3\lib\site-packages\pyparsing.py in parseString(self, instring, parseAll)
   1954                     exc.__traceback__ = self._trim_traceback(exc.__traceback__)
-> 1955                 raise exc
   1956         else:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in unknown_symbol(self, s, loc, toks)
   2766         c = toks[0]
-> 2767         raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)
   2768 

ParseFatalException: Unknown symbol: \gama, found '\'  (at char 0), (line:1, col:1)

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-22-00a5c49fae76> in <module>
     34 
     35 if __name__=="__main__":
---> 36     svmplot(x,y,svmmodel_param)

<ipython-input-22-00a5c49fae76> in svmplot(x, y, svm_param)
     18         svmmodel,title,acc_score=svmModel(x,y,param)
     19         svmsubplot(i,title,svmmodel,grid_test,x1,x2,cm_light,cm_dark,x1_min,x1_max,x2_min,x2_max)
---> 20     plt.tight_layout(1.4)
     21     plt.subplots_adjust(top=0.92)
     22     plt.xlabel("xlabel",fontsize=8)

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*args, **kwargs)
    449                 "parameter will become keyword-only %(removal)s.",
    450                 name=name, obj_type=f"parameter of {func.__name__}()")
--> 451         return func(*args, **kwargs)
    452 
    453     return wrapper

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in tight_layout(pad, h_pad, w_pad, rect)
   1504         subplots area (including labels) will fit.
   1505     """
-> 1506     gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
   1507 
   1508 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py in tight_layout(self, renderer, pad, h_pad, w_pad, rect)
   2611                else suppress())
   2612         with ctx:
-> 2613             kwargs = get_tight_layout_figure(
   2614                 self, self.axes, subplotspec_list, renderer,
   2615                 pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\tight_layout.py in get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, pad, h_pad, w_pad, rect)
    301                               (colNum2 + 1) * div_col - 1))
    302 
--> 303     kwargs = auto_adjust_subplotpars(fig, renderer,
    304                                      nrows_ncols=(max_nrows, max_ncols),
    305                                      num1num2_list=num1num2_list,

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\tight_layout.py in auto_adjust_subplotpars(fig, renderer, nrows_ncols, num1num2_list, subplot_list, ax_bbox_list, pad, h_pad, w_pad, rect)
     82             if ax.get_visible():
     83                 try:
---> 84                     bb += [ax.get_tightbbox(renderer, for_layout_only=True)]
     85                 except TypeError:
     86                     bb += [ax.get_tightbbox(renderer)]

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in get_tightbbox(self, renderer, call_axes_locator, bbox_extra_artists, for_layout_only)
   4167                 if bb_yaxis:
   4168                     bb.append(bb_yaxis)
-> 4169         self._update_title_position(renderer)
   4170         axbbox = self.get_window_extent(renderer)
   4171         bb.append(axbbox)

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _update_title_position(self, renderer)
   2646                 _log.debug('top of axes not in the figure, so title not moved')
   2647                 return
-> 2648             if title.get_window_extent(renderer).ymin < top:
   2649                 _, y = self.transAxes.inverted().transform((0, top))
   2650                 title.set_position((x, y))

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
    900 
    901         with cbook._setattr_cm(self.figure, dpi=dpi):
--> 902             bbox, info, descent = self._get_layout(self._renderer)
    903             x, y = self.get_unitless_position()
    904             x, y = self.get_transform().transform((x, y))

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
    293             clean_line, ismath = self._preprocess_math(line)
    294             if clean_line:
--> 295                 w, h, d = renderer.get_text_width_height_descent(
    296                     clean_line, self._fontproperties, ismath=ismath)
    297             else:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
    231         if ismath:
    232             ox, oy, width, height, descent, fonts, used_characters = \
--> 233                 self.mathtext_parser.parse(s, self.dpi, prop)
    234             return width, height, descent
    235 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, dpi, prop)
   3330         # mathtext.fontset rcParams also affect the parse (e.g. by affecting
   3331         # the glyph metrics).
-> 3332         return self._parse_cached(
   3333             s, dpi, prop, rcParams['ps.useafm'], rcParams['mathtext.fontset'])
   3334 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in _parse_cached(self, s, dpi, prop, ps_useafm, fontset)
   3354             self.__class__._parser = Parser()
   3355 
-> 3356         box = self._parser.parse(s, font_output, fontsize, dpi)
   3357         font_output.set_canvas_size(box.width, box.height, box.depth)
   3358         return font_output.get_results(box)

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, fonts_object, fontsize, dpi)
   2609             result = self._expression.parseString(s)
   2610         except ParseBaseException as err:
-> 2611             raise ValueError("\n".join(["",
   2612                                         err.line,
   2613                                         " " * (err.column - 1) + "^",

ValueError: 
\gama
^
Unknown symbol: \gama, found '\'  (at char 0), (line:1, col:1)

---------------------------------------------------------------------------
ParseFatalException                       Traceback (most recent call last)
d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, fonts_object, fontsize, dpi)
   2608         try:
-> 2609             result = self._expression.parseString(s)
   2610         except ParseBaseException as err:

d:\ProgramData\Anaconda3\lib\site-packages\pyparsing.py in parseString(self, instring, parseAll)
   1954                     exc.__traceback__ = self._trim_traceback(exc.__traceback__)
-> 1955                 raise exc
   1956         else:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in unknown_symbol(self, s, loc, toks)
   2766         c = toks[0]
-> 2767         raise ParseFatalException(s, loc, "Unknown symbol: %s" % c)
   2768 

ParseFatalException: Unknown symbol: \gama, found '\'  (at char 0), (line:1, col:1)

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
d:\ProgramData\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

d:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    246 
    247     if 'png' in formats:
--> 248         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    249     if 'retina' in formats or 'png2x' in formats:
    250         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

d:\ProgramData\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    130         FigureCanvasBase(fig)
    131 
--> 132     fig.canvas.print_figure(bytes_io, **kw)
    133     data = bytes_io.getvalue()
    134     if fmt == 'svg':

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2191                            else suppress())
   2192                     with ctx:
-> 2193                         self.figure.draw(renderer)
   2194 
   2195                     bbox_inches = self.figure.get_tightbbox(

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1861 
   1862             self.patch.draw(renderer)
-> 1863             mimage._draw_list_compositing_images(
   1864                 renderer, self, artists, self.suppressComposite)
   1865 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2705                 artists.remove(spine)
   2706 
-> 2707         self._update_title_position(renderer)
   2708 
   2709         if not self.axison or inframe:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _update_title_position(self, renderer)
   2646                 _log.debug('top of axes not in the figure, so title not moved')
   2647                 return
-> 2648             if title.get_window_extent(renderer).ymin < top:
   2649                 _, y = self.transAxes.inverted().transform((0, top))
   2650                 title.set_position((x, y))

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
    900 
    901         with cbook._setattr_cm(self.figure, dpi=dpi):
--> 902             bbox, info, descent = self._get_layout(self._renderer)
    903             x, y = self.get_unitless_position()
    904             x, y = self.get_transform().transform((x, y))

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
    293             clean_line, ismath = self._preprocess_math(line)
    294             if clean_line:
--> 295                 w, h, d = renderer.get_text_width_height_descent(
    296                     clean_line, self._fontproperties, ismath=ismath)
    297             else:

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
    231         if ismath:
    232             ox, oy, width, height, descent, fonts, used_characters = \
--> 233                 self.mathtext_parser.parse(s, self.dpi, prop)
    234             return width, height, descent
    235 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, dpi, prop)
   3330         # mathtext.fontset rcParams also affect the parse (e.g. by affecting
   3331         # the glyph metrics).
-> 3332         return self._parse_cached(
   3333             s, dpi, prop, rcParams['ps.useafm'], rcParams['mathtext.fontset'])
   3334 

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in _parse_cached(self, s, dpi, prop, ps_useafm, fontset)
   3354             self.__class__._parser = Parser()
   3355 
-> 3356         box = self._parser.parse(s, font_output, fontsize, dpi)
   3357         font_output.set_canvas_size(box.width, box.height, box.depth)
   3358         return font_output.get_results(box)

d:\ProgramData\Anaconda3\lib\site-packages\matplotlib\mathtext.py in parse(self, s, fonts_object, fontsize, dpi)
   2609             result = self._expression.parseString(s)
   2610         except ParseBaseException as err:
-> 2611             raise ValueError("\n".join(["",
   2612                                         err.line,
   2613                                         " " * (err.column - 1) + "^",

ValueError: 
\gama
^
Unknown symbol: \gama, found '\'  (at char 0), (line:1, col:1)

<Figure size 360x144 with 3 Axes>

问题出在title函数上,因为我的title里面有\gama字符,把这一句plt.title(title,fontsize=8)注释掉就可以运行了,暂时还没找到其他好的解决方法。

可以参考这篇博文:

https://blog.csdn.net/seeseaXi/article/details/128506673

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值