代码报错,请修改:ValueError Traceback (most recent call last)
Cell In[2], line 67
65 plt.legend()
66 plt.axis('equal')
---> 67 plt.tight_layout()
68 plt.show()
70 # 打印最终估计
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\pyplot.py:2835, in tight_layout(pad, h_pad, w_pad, rect)
2827 @_copy_docstring_and_deprecators(Figure.tight_layout)
2828 def tight_layout(
2829 *,
(...)
2833 rect: tuple[float, float, float, float] | None = None,
2834 ) -> None:
-> 2835 gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\figure.py:3640, in Figure.tight_layout(self, pad, h_pad, w_pad, rect)
3638 previous_engine = self.get_layout_engine()
3639 self.set_layout_engine(engine)
-> 3640 engine.execute(self)
3641 if previous_engine is not None and not isinstance(
3642 previous_engine, (TightLayoutEngine, PlaceHolderLayoutEngine)
3643 ):
3644 _api.warn_external('The figure layout has changed to tight')
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\layout_engine.py:183, in TightLayoutEngine.execute(self, fig)
181 renderer = fig._get_renderer()
182 with getattr(renderer, "_draw_disabled", nullcontext)():
--> 183 kwargs = get_tight_layout_figure(
184 fig, fig.axes, get_subplotspec_list(fig.axes), renderer,
185 pad=info['pad'], h_pad=info['h_pad'], w_pad=info['w_pad'],
186 rect=info['rect'])
187 if kwargs:
188 fig.subplots_adjust(**kwargs)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_tight_layout.py:266, in get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, pad, h_pad, w_pad, rect)
261 return {}
262 span_pairs.append((
263 slice(ss.rowspan.start * div_row, ss.rowspan.stop * div_row),
264 slice(ss.colspan.start * div_col, ss.colspan.stop * div_col)))
--> 266 kwargs = _auto_adjust_subplotpars(fig, renderer,
267 shape=(max_nrows, max_ncols),
268 span_pairs=span_pairs,
269 subplot_list=subplot_list,
270 ax_bbox_list=ax_bbox_list,
271 pad=pad, h_pad=h_pad, w_pad=w_pad)
273 # kwargs can be none if tight_layout fails...
274 if rect is not None and kwargs is not None:
275 # if rect is given, the whole subplots area (including
276 # labels) will fit into the rect instead of the
(...)
280 # auto_adjust_subplotpars twice, where the second run
281 # with adjusted rect parameters.
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_tight_layout.py:82, in _auto_adjust_subplotpars(fig, renderer, shape, span_pairs, subplot_list, ax_bbox_list, pad, h_pad, w_pad, rect)
80 for ax in subplots:
81 if ax.get_visible():
---> 82 bb += [martist._get_tightbbox_for_layout_only(ax, renderer)]
84 tight_bbox_raw = Bbox.union(bb)
85 tight_bbox = fig.transFigure.inverted().transform_bbox(tight_bbox_raw)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:1402, in _get_tightbbox_for_layout_only(obj, *args, **kwargs)
1396 """
1397 Matplotlib's `.Axes.get_tightbbox` and `.Axis.get_tightbbox` support a
1398 *for_layout_only* kwarg; this helper tries to use the kwarg but skips it
1399 when encountering third-party subclasses that do not support it.
1400 """
1401 try:
-> 1402 return obj.get_tightbbox(*args, **{**kwargs, "for_layout_only": True})
1403 except TypeError:
1404 return obj.get_tightbbox(*args, **kwargs)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\axes\_base.py:4542, in _AxesBase.get_tightbbox(self, renderer, call_axes_locator, bbox_extra_artists, for_layout_only)
4539 bbox_artists = self.get_default_bbox_extra_artists()
4541 for a in bbox_artists:
-> 4542 bbox = a.get_tightbbox(renderer)
4543 if (bbox is not None
4544 and 0 < bbox.width < np.inf
4545 and 0 < bbox.height < np.inf):
4546 bb.append(bbox)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\legend.py:1059, in Legend.get_tightbbox(self, renderer)
1057 def get_tightbbox(self, renderer=None):
1058 # docstring inherited
-> 1059 return self._legend_box.get_window_extent(renderer)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:367, in OffsetBox.get_window_extent(self, renderer)
365 if renderer is None:
366 renderer = self.get_figure(root=True)._get_renderer()
--> 367 bbox = self.get_bbox(renderer)
368 try: # Some subclasses redefine get_offset to take no args.
369 px, py = self.get_offset(bbox, renderer)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:767, in TextArea.get_bbox(self, renderer)
762 def get_bbox(self, renderer):
763 _, h_, d_ = renderer.get_text_width_height_descent(
764 "lp", self._text._fontproperties,
765 ismath="TeX" if self._text.get_usetex() else False)
--> 767 bbox, info, yd = self._text._get_layout(renderer)
768 w, h = bbox.size
770 self._baseline_transform.clear()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:382, in Text._get_layout(self, renderer)
380 clean_line, ismath = self._preprocess_math(line)
381 if clean_line:
--> 382 w, h, d = _get_text_metrics_with_cache(
383 renderer, clean_line, self._fontproperties,
384 ismath=ismath, dpi=self.get_figure(root=True).dpi)
385 else:
386 w = h = d = 0
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:69, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
66 """Call ``renderer.get_text_width_height_descent``, caching the results."""
67 # Cached based on a copy of fontprop so that later in-place mutations of
68 # the passed-in argument do not mess up the cache.
---> 69 return _get_text_metrics_with_cache_impl(
70 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:77, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
73 @functools.lru_cache(4096)
74 def _get_text_metrics_with_cache_impl(
75 renderer_ref, text, fontprop, ismath, dpi):
76 # dpi is unused, but participates in cache invalidation (via the renderer).
---> 77 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:215, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
211 return super().get_text_width_height_descent(s, prop, ismath)
213 if ismath:
214 ox, oy, width, height, descent, font_image = \
--> 215 self.mathtext_parser.parse(s, self.dpi, prop)
216 return width, height, descent
218 font = self._prepare_font(prop)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:86, in MathTextParser.parse(self, s, dpi, prop, antialiased)
81 from matplotlib.backends import backend_agg
82 load_glyph_flags = {
83 "vector": LoadFlags.NO_HINTING,
84 "raster": backend_agg.get_hinting_flag(),
85 }[self._output_type]
---> 86 return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:100, in MathTextParser._parse_cached(self, s, dpi, prop, antialiased, load_glyph_flags)
97 if self._parser is None: # Cache the parser globally.
98 self.__class__._parser = _mathtext.Parser()
--> 100 box = self._parser.parse(s, fontset, fontsize, dpi)
101 output = _mathtext.ship(box)
102 if self._output_type == "vector":
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_mathtext.py:2173, in Parser.parse(self, s, fonts_object, fontsize, dpi)
2170 result = self._expression.parseString(s)
2171 except ParseBaseException as err:
2172 # explain becomes a plain method on pyparsing 3 (err.explain(0)).
-> 2173 raise ValueError("\n" + ParseException.explain(err, 0)) from None
2174 self._state_stack = []
2175 self._in_subscript_or_superscript = False
ValueError:
True $eta$
^
ParseException: Expected end of text, found '$' (at char 5), (line:1, col:6)
Error in callback <function _draw_all_if_interactive at 0x000001ABB2E52AC0> (for post_execute), with arguments args (),kwargs {}:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\pyplot.py:279, in _draw_all_if_interactive()
277 def _draw_all_if_interactive() -> None:
278 if matplotlib.is_interactive():
--> 279 draw_all()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_pylab_helpers.py:131, in Gcf.draw_all(cls, force)
129 for manager in cls.get_all_fig_managers():
130 if force or manager.canvas.figure.stale:
--> 131 manager.canvas.draw_idle()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:1891, in FigureCanvasBase.draw_idle(self, *args, **kwargs)
1889 if not self._is_idle_drawing:
1890 with self._idle_draw_cntx():
-> 1891 self.draw(*args, **kwargs)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:382, in FigureCanvasAgg.draw(self)
379 # Acquire a lock on the shared font cache.
380 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
381 else nullcontext()):
--> 382 self.figure.draw(self.renderer)
383 # A GUI class may be need to update a window using this draw, so
384 # don't forget to call the superclass.
385 super().draw()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:94, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
92 @wraps(draw)
93 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 94 result = draw(artist, renderer, *args, **kwargs)
95 if renderer._rasterizing:
96 renderer.stop_rasterizing()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\figure.py:3257, in Figure.draw(self, renderer)
3254 # ValueError can occur when resizing a window.
3256 self.patch.draw(renderer)
-> 3257 mimage._draw_list_compositing_images(
3258 renderer, self, artists, self.suppressComposite)
3260 renderer.close_group('figure')
3261 finally:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
132 if not_composite or not has_images:
133 for a in artists:
--> 134 a.draw(renderer)
135 else:
136 # Composite any adjacent images together
137 image_group = []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\axes\_base.py:3181, in _AxesBase.draw(self, renderer)
3178 if artists_rasterized:
3179 _draw_rasterized(self.get_figure(root=True), artists_rasterized, renderer)
-> 3181 mimage._draw_list_compositing_images(
3182 renderer, self, artists, self.get_figure(root=True).suppressComposite)
3184 renderer.close_group('axes')
3185 self.stale = False
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
132 if not_composite or not has_images:
133 for a in artists:
--> 134 a.draw(renderer)
135 else:
136 # Composite any adjacent images together
137 image_group = []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\legend.py:752, in Legend.draw(self, renderer)
748 self._legend_box.set_width(self.get_bbox_to_anchor().width - pad)
750 # update the location and size of the legend. This needs to
751 # be done in any case to clip the figure right.
--> 752 bbox = self._legend_box.get_window_extent(renderer)
753 self.legendPatch.set_bounds(bbox.bounds)
754 self.legendPatch.set_mutation_scale(fontsize)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:367, in OffsetBox.get_window_extent(self, renderer)
365 if renderer is None:
366 renderer = self.get_figure(root=True)._get_renderer()
--> 367 bbox = self.get_bbox(renderer)
368 try: # Some subclasses redefine get_offset to take no args.
369 px, py = self.get_offset(bbox, renderer)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:767, in TextArea.get_bbox(self, renderer)
762 def get_bbox(self, renderer):
763 _, h_, d_ = renderer.get_text_width_height_descent(
764 "lp", self._text._fontproperties,
765 ismath="TeX" if self._text.get_usetex() else False)
--> 767 bbox, info, yd = self._text._get_layout(renderer)
768 w, h = bbox.size
770 self._baseline_transform.clear()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:382, in Text._get_layout(self, renderer)
380 clean_line, ismath = self._preprocess_math(line)
381 if clean_line:
--> 382 w, h, d = _get_text_metrics_with_cache(
383 renderer, clean_line, self._fontproperties,
384 ismath=ismath, dpi=self.get_figure(root=True).dpi)
385 else:
386 w = h = d = 0
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:69, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
66 """Call ``renderer.get_text_width_height_descent``, caching the results."""
67 # Cached based on a copy of fontprop so that later in-place mutations of
68 # the passed-in argument do not mess up the cache.
---> 69 return _get_text_metrics_with_cache_impl(
70 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:77, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
73 @functools.lru_cache(4096)
74 def _get_text_metrics_with_cache_impl(
75 renderer_ref, text, fontprop, ismath, dpi):
76 # dpi is unused, but participates in cache invalidation (via the renderer).
---> 77 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:215, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
211 return super().get_text_width_height_descent(s, prop, ismath)
213 if ismath:
214 ox, oy, width, height, descent, font_image = \
--> 215 self.mathtext_parser.parse(s, self.dpi, prop)
216 return width, height, descent
218 font = self._prepare_font(prop)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:86, in MathTextParser.parse(self, s, dpi, prop, antialiased)
81 from matplotlib.backends import backend_agg
82 load_glyph_flags = {
83 "vector": LoadFlags.NO_HINTING,
84 "raster": backend_agg.get_hinting_flag(),
85 }[self._output_type]
---> 86 return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:100, in MathTextParser._parse_cached(self, s, dpi, prop, antialiased, load_glyph_flags)
97 if self._parser is None: # Cache the parser globally.
98 self.__class__._parser = _mathtext.Parser()
--> 100 box = self._parser.parse(s, fontset, fontsize, dpi)
101 output = _mathtext.ship(box)
102 if self._output_type == "vector":
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_mathtext.py:2173, in Parser.parse(self, s, fonts_object, fontsize, dpi)
2170 result = self._expression.parseString(s)
2171 except ParseBaseException as err:
2172 # explain becomes a plain method on pyparsing 3 (err.explain(0)).
-> 2173 raise ValueError("\n" + ParseException.explain(err, 0)) from None
2174 self._state_stack = []
2175 self._in_subscript_or_superscript = False
ValueError:
True $eta$
^
ParseException: Expected end of text, found '$' (at char 5), (line:1, col:6)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\formatters.py:402, in BaseFormatter.__call__(self, obj)
400 pass
401 else:
--> 402 return printer(obj)
403 # Finally look for special method names
404 method = get_real_method(obj, self.print_method)
File C:\ProgramData\anaconda3\Lib\site-packages\IPython\core\pylabtools.py:170, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
167 from matplotlib.backend_bases import FigureCanvasBase
168 FigureCanvasBase(fig)
--> 170 fig.canvas.print_figure(bytes_io, **kw)
171 data = bytes_io.getvalue()
172 if fmt == 'svg':
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:2155, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2152 # we do this instead of `self.figure.draw_without_rendering`
2153 # so that we can inject the orientation
2154 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2155 self.figure.draw(renderer)
2156 if bbox_inches:
2157 if bbox_inches == "tight":
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:94, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
92 @wraps(draw)
93 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 94 result = draw(artist, renderer, *args, **kwargs)
95 if renderer._rasterizing:
96 renderer.stop_rasterizing()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\figure.py:3257, in Figure.draw(self, renderer)
3254 # ValueError can occur when resizing a window.
3256 self.patch.draw(renderer)
-> 3257 mimage._draw_list_compositing_images(
3258 renderer, self, artists, self.suppressComposite)
3260 renderer.close_group('figure')
3261 finally:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
132 if not_composite or not has_images:
133 for a in artists:
--> 134 a.draw(renderer)
135 else:
136 # Composite any adjacent images together
137 image_group = []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\axes\_base.py:3181, in _AxesBase.draw(self, renderer)
3178 if artists_rasterized:
3179 _draw_rasterized(self.get_figure(root=True), artists_rasterized, renderer)
-> 3181 mimage._draw_list_compositing_images(
3182 renderer, self, artists, self.get_figure(root=True).suppressComposite)
3184 renderer.close_group('axes')
3185 self.stale = False
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\image.py:134, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
132 if not_composite or not has_images:
133 for a in artists:
--> 134 a.draw(renderer)
135 else:
136 # Composite any adjacent images together
137 image_group = []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\artist.py:71, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
68 if artist.get_agg_filter() is not None:
69 renderer.start_filter()
---> 71 return draw(artist, renderer)
72 finally:
73 if artist.get_agg_filter() is not None:
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\legend.py:752, in Legend.draw(self, renderer)
748 self._legend_box.set_width(self.get_bbox_to_anchor().width - pad)
750 # update the location and size of the legend. This needs to
751 # be done in any case to clip the figure right.
--> 752 bbox = self._legend_box.get_window_extent(renderer)
753 self.legendPatch.set_bounds(bbox.bounds)
754 self.legendPatch.set_mutation_scale(fontsize)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:367, in OffsetBox.get_window_extent(self, renderer)
365 if renderer is None:
366 renderer = self.get_figure(root=True)._get_renderer()
--> 367 bbox = self.get_bbox(renderer)
368 try: # Some subclasses redefine get_offset to take no args.
369 px, py = self.get_offset(bbox, renderer)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:452, in VPacker._get_bbox_and_child_offsets(self, renderer)
449 if isinstance(c, PackerBase) and c.mode == "expand":
450 c.set_width(self.width)
--> 452 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
453 (x0, x1), xoffsets = _get_aligned_offsets(
454 [bbox.intervalx for bbox in bboxes], self.width, self.align)
455 height, yoffsets = _get_packed_offsets(
456 [bbox.height for bbox in bboxes], self.height, sep, self.mode)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:360, in OffsetBox.get_bbox(self, renderer)
358 def get_bbox(self, renderer):
359 """Return the bbox of the offsetbox, ignoring parent offsets."""
--> 360 bbox, offsets = self._get_bbox_and_child_offsets(renderer)
361 return bbox
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:479, in HPacker._get_bbox_and_child_offsets(self, renderer)
476 pad = self.pad * dpicor
477 sep = self.sep * dpicor
--> 479 bboxes = [c.get_bbox(renderer) for c in self.get_visible_children()]
480 if not bboxes:
481 return Bbox.from_bounds(0, 0, 0, 0).padded(pad), []
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\offsetbox.py:767, in TextArea.get_bbox(self, renderer)
762 def get_bbox(self, renderer):
763 _, h_, d_ = renderer.get_text_width_height_descent(
764 "lp", self._text._fontproperties,
765 ismath="TeX" if self._text.get_usetex() else False)
--> 767 bbox, info, yd = self._text._get_layout(renderer)
768 w, h = bbox.size
770 self._baseline_transform.clear()
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:382, in Text._get_layout(self, renderer)
380 clean_line, ismath = self._preprocess_math(line)
381 if clean_line:
--> 382 w, h, d = _get_text_metrics_with_cache(
383 renderer, clean_line, self._fontproperties,
384 ismath=ismath, dpi=self.get_figure(root=True).dpi)
385 else:
386 w = h = d = 0
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:69, in _get_text_metrics_with_cache(renderer, text, fontprop, ismath, dpi)
66 """Call ``renderer.get_text_width_height_descent``, caching the results."""
67 # Cached based on a copy of fontprop so that later in-place mutations of
68 # the passed-in argument do not mess up the cache.
---> 69 return _get_text_metrics_with_cache_impl(
70 weakref.ref(renderer), text, fontprop.copy(), ismath, dpi)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\text.py:77, in _get_text_metrics_with_cache_impl(renderer_ref, text, fontprop, ismath, dpi)
73 @functools.lru_cache(4096)
74 def _get_text_metrics_with_cache_impl(
75 renderer_ref, text, fontprop, ismath, dpi):
76 # dpi is unused, but participates in cache invalidation (via the renderer).
---> 77 return renderer_ref().get_text_width_height_descent(text, fontprop, ismath)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:215, in RendererAgg.get_text_width_height_descent(self, s, prop, ismath)
211 return super().get_text_width_height_descent(s, prop, ismath)
213 if ismath:
214 ox, oy, width, height, descent, font_image = \
--> 215 self.mathtext_parser.parse(s, self.dpi, prop)
216 return width, height, descent
218 font = self._prepare_font(prop)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:86, in MathTextParser.parse(self, s, dpi, prop, antialiased)
81 from matplotlib.backends import backend_agg
82 load_glyph_flags = {
83 "vector": LoadFlags.NO_HINTING,
84 "raster": backend_agg.get_hinting_flag(),
85 }[self._output_type]
---> 86 return self._parse_cached(s, dpi, prop, antialiased, load_glyph_flags)
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\mathtext.py:100, in MathTextParser._parse_cached(self, s, dpi, prop, antialiased, load_glyph_flags)
97 if self._parser is None: # Cache the parser globally.
98 self.__class__._parser = _mathtext.Parser()
--> 100 box = self._parser.parse(s, fontset, fontsize, dpi)
101 output = _mathtext.ship(box)
102 if self._output_type == "vector":
File C:\ProgramData\anaconda3\Lib\site-packages\matplotlib\_mathtext.py:2173, in Parser.parse(self, s, fonts_object, fontsize, dpi)
2170 result = self._expression.parseString(s)
2171 except ParseBaseException as err:
2172 # explain becomes a plain method on pyparsing 3 (err.explain(0)).
-> 2173 raise ValueError("\n" + ParseException.explain(err, 0)) from None
2174 self._state_stack = []
2175 self._in_subscript_or_superscript = False
ValueError:
True $eta$
^
ParseException: Expected end of text, found '$' (at char 5), (line:1, col:6)
<Figure size 800x600 with 1 Axes>
最新发布