matplotlibのバージョン変更したら、下記のエラーが発生した。
Error in callback .post_execute at 0x7f6fddedc8c0> (for post_execute):
エラー内容
TypeError Traceback (most recent call last)
/opt/anaconda3/lib/python3.7/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)
/opt/anaconda3/lib/python3.7/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
244 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
245 if 'retina' in formats or 'png2x' in formats:
--> 246 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
247 if 'jpg' in formats or 'jpeg' in formats:
248 jpg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'jpg', **kwargs))
/opt/anaconda3/lib/python3.7/site-packages/IPython/core/pylabtools.py in retina_figure(fig, **kwargs)
134 def retina_figure(fig, **kwargs):
135 """format a figure as a pixel-doubled (retina) PNG"""
--> 136 pngdata = print_figure(fig, fmt='retina', **kwargs)
137 # Make sure that retina_figure acts just like print_figure and returns
138 # None when the figure is empty.
/opt/anaconda3/lib/python3.7/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
126
127 bytes_io = BytesIO()
--> 128 fig.canvas.print_figure(bytes_io, **kw)
129 data = bytes_io.getvalue()
130 if fmt == 'svg':
/opt/anaconda3/lib/python3.7/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)
2259 orientation=orientation,
2260 bbox_inches_restore=_bbox_inches_restore,
-> 2261 **kwargs)
2262 finally:
2263 if bbox_inches and restore_bbox:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
1667 kwargs.pop(arg)
1668
-> 1669 return func(*args, **kwargs)
1670
1671 return wrapper
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
506 *metadata*, including the default 'Software' key.
507 """
--> 508 FigureCanvasAgg.draw(self)
509 mpl.image.imsave(
510 filename_or_obj, self.buffer_rgba(), format="png", origin="upper",
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py in draw(self)
404 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
405 else nullcontext()):
--> 406 self.figure.draw(self.renderer)
407 # A GUI class may be need to update a window using this draw, so
408 # don't forget to call the superclass.
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
72 @wraps(draw)
73 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74 result = draw(artist, renderer, *args, **kwargs)
75 if renderer._rasterizing:
76 renderer.stop_rasterizing()
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py in draw(self, renderer)
2789 self.patch.draw(renderer)
2790 mimage._draw_list_compositing_images(
-> 2791 renderer, self, artists, self.suppressComposite)
2792
2793 for sfig in self.subfigs:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2919 renderer.stop_rasterizing()
2920
-> 2921 mimage._draw_list_compositing_images(renderer, self, artists)
2922
2923 renderer.close_group('axes')
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in draw(self, renderer)
1010 def draw(self, renderer):
1011 self.set_sizes(self._sizes, self.figure.dpi)
-> 1012 super().draw(renderer)
1013
1014
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in draw(self, renderer)
406 renderer.draw_markers(
407 gc, paths[0], combined_transform.frozen(),
--> 408 mpath.Path(offsets), transOffset, tuple(facecolors[0]))
409 else:
410 renderer.draw_path_collection(
TypeError: must be real number, not str
<Figure size 360x360 with 1 Axes>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-23-cb00f7dac148> in <module>
26 edgecolors="red")
27 plt.show()
---> 28 fig.savefig(f'./plot_fig/{date}_{fold}.png')
29
30 models.append(model)
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
3013 patch.set_edgecolor('none')
3014
-> 3015 self.canvas.print_figure(fname, **kwargs)
3016
3017 if transparent:
/opt/anaconda3/lib/python3.7/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)
2259 orientation=orientation,
2260 bbox_inches_restore=_bbox_inches_restore,
-> 2261 **kwargs)
2262 finally:
2263 if bbox_inches and restore_bbox:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backend_bases.py in wrapper(*args, **kwargs)
1667 kwargs.pop(arg)
1668
-> 1669 return func(*args, **kwargs)
1670
1671 return wrapper
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args)
506 *metadata*, including the default 'Software' key.
507 """
--> 508 FigureCanvasAgg.draw(self)
509 mpl.image.imsave(
510 filename_or_obj, self.buffer_rgba(), format="png", origin="upper",
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py in draw(self)
404 (self.toolbar._wait_cursor_for_draw_cm() if self.toolbar
405 else nullcontext()):
--> 406 self.figure.draw(self.renderer)
407 # A GUI class may be need to update a window using this draw, so
408 # don't forget to call the superclass.
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
72 @wraps(draw)
73 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 74 result = draw(artist, renderer, *args, **kwargs)
75 if renderer._rasterizing:
76 renderer.stop_rasterizing()
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/figure.py in draw(self, renderer)
2789 self.patch.draw(renderer)
2790 mimage._draw_list_compositing_images(
-> 2791 renderer, self, artists, self.suppressComposite)
2792
2793 for sfig in self.subfigs:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/_api/deprecation.py in wrapper(*inner_args, **inner_kwargs)
429 else deprecation_addendum,
430 **kwargs)
--> 431 return func(*inner_args, **inner_kwargs)
432
433 return wrapper
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2919 renderer.stop_rasterizing()
2920
-> 2921 mimage._draw_list_compositing_images(renderer, self, artists)
2922
2923 renderer.close_group('axes')
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in draw(self, renderer)
1010 def draw(self, renderer):
1011 self.set_sizes(self._sizes, self.figure.dpi)
-> 1012 super().draw(renderer)
1013
1014
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
49 renderer.start_filter()
50
---> 51 return draw(artist, renderer, *args, **kwargs)
52 finally:
53 if artist.get_agg_filter() is not None:
/opt/anaconda3/lib/python3.7/site-packages/matplotlib/collections.py in draw(self, renderer)
406 renderer.draw_markers(
407 gc, paths[0], combined_transform.frozen(),
--> 408 mpath.Path(offsets), transOffset, tuple(facecolors[0]))
409 else:
410 renderer.draw_path_collection(
TypeError: must be real number, not str
該当のコード
fig = plt.figure(figsize=(5, 5))
plt.xlim([0, 2])
plt.ylim([0, 2])
plt.xlabel("true")
plt.ylabel("pred")
plt.scatter(trues, preds, s=400, c="pink", alpha=0.5, linewidths="2",
edgecolors="red")
plt.show()
解決法
linewidths="2" を
linewidths=2 に変更