Код: Выделить всё
import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
X = np.random.randn(50)
Y = np.random.randn(50)
plt.scatter(X,Y)
plt.show()
ValueError: метод объекта array не создает массив
Окружающая среда:
- Windows 11
- Anaconda-клиент 1.12.3
- numpy 1.26.4
- tensorflow 2.18.0
- matplotlib 3.9.2
Код: Выделить всё
ValueError Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\IPython\core\formatters.py:343, in BaseFormatter.__call__(self, obj)
341 pass
342 else:
--> 343 return printer(obj)
344 # Finally look for special method names
345 method = get_real_method(obj, self.print_method)
File ~\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 ~\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:2204, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2200 try:
2201 # _get_renderer may change the figure dpi (as vector formats
2202 # force the figure dpi to 72), so we need to set it again here.
2203 with cbook._setattr_cm(self.figure, dpi=dpi):
-> 2204 result = print_method(
2205 filename,
2206 facecolor=facecolor,
2207 edgecolor=edgecolor,
2208 orientation=orientation,
2209 bbox_inches_restore=_bbox_inches_restore,
2210 **kwargs)
2211 finally:
2212 if bbox_inches and restore_bbox:
File ~\anaconda3\Lib\site-packages\matplotlib\backend_bases.py:2054, in FigureCanvasBase._switch_canvas_and_return_print_method..(*args, **kwargs)
2050 optional_kws = { # Passed by print_figure for other renderers.
2051 "dpi", "facecolor", "edgecolor", "orientation",
2052 "bbox_inches_restore"}
2053 skip = optional_kws - {*inspect.signature(meth).parameters}
-> 2054 print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
2055 *args, **{k: v for k, v in kwargs.items() if k not in skip}))
2056 else: # Let third-parties do as they see fit.
2057 print_method = meth
File ~\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:496, in FigureCanvasAgg.print_png(self, filename_or_obj, metadata, pil_kwargs)
449 def print_png(self, filename_or_obj, *, metadata=None, pil_kwargs=None):
450 """
451 Write the figure to a PNG file.
452
(...)
494 *metadata*, including the default 'Software' key.
495 """
--> 496 self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
File ~\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:444, in FigureCanvasAgg._print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata)
439 def _print_pil(self, filename_or_obj, fmt, pil_kwargs, metadata=None):
440 """
441 Draw the canvas, then save it using `.image.imsave` (to which
442 *pil_kwargs* and *metadata* are forwarded).
443 """
--> 444 FigureCanvasAgg.draw(self)
445 mpl.image.imsave(
446 filename_or_obj, self.buffer_rgba(), format=fmt, origin="upper",
447 dpi=self.figure.dpi, metadata=metadata, pil_kwargs=pil_kwargs)
File ~\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:387, in FigureCanvasAgg.draw(self)
384 # Acquire a lock on the shared font cache.
385 with (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
386 else nullcontext()):
--> 387 self.figure.draw(self.renderer)
388 # A GUI class may be need to update a window using this draw, so
389 # don't forget to call the superclass.
390 super().draw()
File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:95, in _finalize_rasterization..draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File ~\anaconda3\Lib\site-packages\matplotlib\figure.py:3161, in Figure.draw(self, renderer)
3158 pass
3159 # ValueError can occur when resizing a window.
-> 3161 self.patch.draw(renderer)
3162 mimage._draw_list_compositing_images(
3163 renderer, self, artists, self.suppressComposite)
3165 renderer.close_group('figure')
File ~\anaconda3\Lib\site-packages\matplotlib\artist.py:72, in allow_rasterization..draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File ~\anaconda3\Lib\site-packages\matplotlib\patches.py:632, in Patch.draw(self, renderer)
630 tpath = transform.transform_path_non_affine(path)
631 affine = transform.get_affine()
--> 632 self._draw_paths_with_artist_properties(
633 renderer,
634 [(tpath, affine,
635 # Work around a bug in the PDF and SVG renderers, which
636 # do not draw the hatches if the facecolor is fully
637 # transparent, but do if it is None.
638 self._facecolor if self._facecolor[3] else None)])
File ~\anaconda3\Lib\site-packages\matplotlib\patches.py:617, in Patch._draw_paths_with_artist_properties(self, renderer, draw_path_args_list)
614 renderer = PathEffectRenderer(self.get_path_effects(), renderer)
616 for draw_path_args in draw_path_args_list:
--> 617 renderer.draw_path(gc, *draw_path_args)
619 gc.restore()
620 renderer.close_group('patch')
File ~\anaconda3\Lib\site-packages\matplotlib\backends\backend_agg.py:131, in RendererAgg.draw_path(self, gc, path, transform, rgbFace)
129 else:
130 try:
--> 131 self._renderer.draw_path(gc, path, transform, rgbFace)
132 except OverflowError:
133 cant_chunk = ''
ValueError: object __array__ method not producing an array
Подробнее здесь: https://stackoverflow.com/questions/793 ... oducing-an
Мобильная версия