Posts: 2
Threads: 1
Joined: May 2019
Hi!
I've made a figure using matplotlib and now I'm trying to save it to file using matplotlib.pyplot.savefig
import matplotlib.pyplot as plt
# . . .
plt.savefig("result.png") Unfortunately it occurs FileNotFoundError at plt.savefig call.
Does anybody know, how can this problem be solved?
Posts: 8,165
Threads: 160
Joined: Sep 2016
(May-07-2019, 09:54 AM)drinkOut Wrote: Unfortunately it occurs FileNotFoundError at plt.savefig call.
Please post full traceback you get in error tags. Also it would be nice to post full code (minimal verifiable example that reproduce the problem).
Posts: 2
Threads: 1
Joined: May 2019
Jupyter Notebook cell:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
y = [2,4,6,8,10,12,14,16,18,20]
x = np.arange(10)
fig = plt.figure()
ax = plt.subplot(111)
ax.plot(x, y, label='$y = numbers')
plt.title('Legend inside')
ax.legend()
#plt.show()
fig.savefig('plot.png') Error trace:
Quote:---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-38-f686aa71d348> in <module>
14 #plt.show()
15
---> 16 fig.savefig('plot.png')
~\Anaconda3\lib\site-packages\matplotlib\figure.py in savefig(self, fname, frameon, transparent, **kwargs)
2092 self.set_frameon(frameon)
2093
-> 2094 self.canvas.print_figure(fname, **kwargs)
2095
2096 if frameon:
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2047 orientation=orientation,
2048 dryrun=True,
-> 2049 **kwargs)
2050 renderer = self.figure._cachedRenderer
2051 bbox_artists = kwargs.pop("bbox_extra_artists", None)
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
508
509 """
--> 510 FigureCanvasAgg.draw(self)
511 renderer = self.get_renderer()
512
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
400 toolbar = self.toolbar
401 try:
--> 402 self.figure.draw(self.renderer)
403 # A GUI class may be need to update a window using this draw, so
404 # don't forget to call the superclass.
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1647
1648 mimage._draw_list_compositing_images(
-> 1649 renderer, self, artists, self.suppressComposite)
1650
1651 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2626 renderer.stop_rasterizing()
2627
-> 2628 mimage._draw_list_compositing_images(renderer, self, artists)
2629
2630 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1185 ticks_to_draw = self._update_ticks(renderer)
1186 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1187 renderer)
1188
1189 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1123 for tick in ticks:
1124 if tick.label1On and tick.label1.get_visible():
-> 1125 extent = tick.label1.get_window_extent(renderer)
1126 ticklabelBoxes.append(extent)
1127 if tick.label2On and tick.label2.get_visible():
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
928 raise RuntimeError('Cannot get window extent w/o renderer')
929
--> 930 bbox, info, descent = self._get_layout(self._renderer)
931 x, y = self.get_unitless_position()
932 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
311 w, h, d = renderer.get_text_width_height_descent(clean_line,
312 self._fontproperties,
--> 313 ismath=ismath)
314 else:
315 w, h, d = 0, 0, 0
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
207 fontsize = prop.get_size_in_points()
208 w, h, d = texmanager.get_text_width_height_descent(
--> 209 s, fontsize, renderer=self)
210 return w, h, d
211
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
462 else:
463 # use dviread. It sometimes returns a wrong descent.
--> 464 dvifile = self.make_dvi(tex, fontsize)
465 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
466 page = next(iter(dvi))
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
326 self._run_checked_subprocess(
327 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 328 texfile], tex)
329 for fname in glob.glob(basefile + '*'):
330 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
296 report = subprocess.check_output(command,
297 cwd=self.texcache,
--> 298 stderr=subprocess.STDOUT)
299 except subprocess.CalledProcessError as exc:
300 raise RuntimeError(
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
387
388 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 389 **kwargs).stdout
390
391
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
464 kwargs['stderr'] = PIPE
465
--> 466 with Popen(*popenargs, **kwargs) as process:
467 try:
468 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
767 c2pread, c2pwrite,
768 errread, errwrite,
--> 769 restore_signals, start_new_session)
770 except:
771 # Cleanup if the child failed starting.
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1170 env,
1171 os.fspath(cwd) if cwd is not None else None,
-> 1172 startupinfo)
1173 finally:
1174 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
Error in callback <function install_repl_displayhook.<locals>.post_execute at 0x0000022B088419D8> (for post_execute):
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in post_execute()
107 def post_execute():
108 if matplotlib.is_interactive():
--> 109 draw_all()
110
111 # IPython >= 2
~\Anaconda3\lib\site-packages\matplotlib\_pylab_helpers.py in draw_all(cls, force)
130 for f_mgr in cls.get_all_fig_managers():
131 if force or f_mgr.canvas.figure.stale:
--> 132 f_mgr.canvas.draw_idle()
133
134 atexit.register(Gcf.destroy_all)
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in draw_idle(self, *args, **kwargs)
1897 if not self._is_idle_drawing:
1898 with self._idle_draw_cntx():
-> 1899 self.draw(*args, **kwargs)
1900
1901 def draw_cursor(self, event):
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
400 toolbar = self.toolbar
401 try:
--> 402 self.figure.draw(self.renderer)
403 # A GUI class may be need to update a window using this draw, so
404 # don't forget to call the superclass.
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1647
1648 mimage._draw_list_compositing_images(
-> 1649 renderer, self, artists, self.suppressComposite)
1650
1651 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2626 renderer.stop_rasterizing()
2627
-> 2628 mimage._draw_list_compositing_images(renderer, self, artists)
2629
2630 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1185 ticks_to_draw = self._update_ticks(renderer)
1186 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1187 renderer)
1188
1189 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1123 for tick in ticks:
1124 if tick.label1On and tick.label1.get_visible():
-> 1125 extent = tick.label1.get_window_extent(renderer)
1126 ticklabelBoxes.append(extent)
1127 if tick.label2On and tick.label2.get_visible():
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
928 raise RuntimeError('Cannot get window extent w/o renderer')
929
--> 930 bbox, info, descent = self._get_layout(self._renderer)
931 x, y = self.get_unitless_position()
932 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
311 w, h, d = renderer.get_text_width_height_descent(clean_line,
312 self._fontproperties,
--> 313 ismath=ismath)
314 else:
315 w, h, d = 0, 0, 0
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
207 fontsize = prop.get_size_in_points()
208 w, h, d = texmanager.get_text_width_height_descent(
--> 209 s, fontsize, renderer=self)
210 return w, h, d
211
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
462 else:
463 # use dviread. It sometimes returns a wrong descent.
--> 464 dvifile = self.make_dvi(tex, fontsize)
465 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
466 page = next(iter(dvi))
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
326 self._run_checked_subprocess(
327 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 328 texfile], tex)
329 for fname in glob.glob(basefile + '*'):
330 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
296 report = subprocess.check_output(command,
297 cwd=self.texcache,
--> 298 stderr=subprocess.STDOUT)
299 except subprocess.CalledProcessError as exc:
300 raise RuntimeError(
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
387
388 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 389 **kwargs).stdout
390
391
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
464 kwargs['stderr'] = PIPE
465
--> 466 with Popen(*popenargs, **kwargs) as process:
467 try:
468 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
767 c2pread, c2pwrite,
768 errread, errwrite,
--> 769 restore_signals, start_new_session)
770 except:
771 # Cleanup if the child failed starting.
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1170 env,
1171 os.fspath(cwd) if cwd is not None else None,
-> 1172 startupinfo)
1173 finally:
1174 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\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)
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
242
243 if 'png' in formats:
--> 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))
~\Anaconda3\lib\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':
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2047 orientation=orientation,
2048 dryrun=True,
-> 2049 **kwargs)
2050 renderer = self.figure._cachedRenderer
2051 bbox_artists = kwargs.pop("bbox_extra_artists", None)
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
508
509 """
--> 510 FigureCanvasAgg.draw(self)
511 renderer = self.get_renderer()
512
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
400 toolbar = self.toolbar
401 try:
--> 402 self.figure.draw(self.renderer)
403 # A GUI class may be need to update a window using this draw, so
404 # don't forget to call the superclass.
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1647
1648 mimage._draw_list_compositing_images(
-> 1649 renderer, self, artists, self.suppressComposite)
1650
1651 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2626 renderer.stop_rasterizing()
2627
-> 2628 mimage._draw_list_compositing_images(renderer, self, artists)
2629
2630 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1185 ticks_to_draw = self._update_ticks(renderer)
1186 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1187 renderer)
1188
1189 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1123 for tick in ticks:
1124 if tick.label1On and tick.label1.get_visible():
-> 1125 extent = tick.label1.get_window_extent(renderer)
1126 ticklabelBoxes.append(extent)
1127 if tick.label2On and tick.label2.get_visible():
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
928 raise RuntimeError('Cannot get window extent w/o renderer')
929
--> 930 bbox, info, descent = self._get_layout(self._renderer)
931 x, y = self.get_unitless_position()
932 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
311 w, h, d = renderer.get_text_width_height_descent(clean_line,
312 self._fontproperties,
--> 313 ismath=ismath)
314 else:
315 w, h, d = 0, 0, 0
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in get_text_width_height_descent(self, s, prop, ismath)
207 fontsize = prop.get_size_in_points()
208 w, h, d = texmanager.get_text_width_height_descent(
--> 209 s, fontsize, renderer=self)
210 return w, h, d
211
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
462 else:
463 # use dviread. It sometimes returns a wrong descent.
--> 464 dvifile = self.make_dvi(tex, fontsize)
465 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
466 page = next(iter(dvi))
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
326 self._run_checked_subprocess(
327 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 328 texfile], tex)
329 for fname in glob.glob(basefile + '*'):
330 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
296 report = subprocess.check_output(command,
297 cwd=self.texcache,
--> 298 stderr=subprocess.STDOUT)
299 except subprocess.CalledProcessError as exc:
300 raise RuntimeError(
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
387
388 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 389 **kwargs).stdout
390
391
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
464 kwargs['stderr'] = PIPE
465
--> 466 with Popen(*popenargs, **kwargs) as process:
467 try:
468 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
767 c2pread, c2pwrite,
768 errread, errwrite,
--> 769 restore_signals, start_new_session)
770 except:
771 # Cleanup if the child failed starting.
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1170 env,
1171 os.fspath(cwd) if cwd is not None else None,
-> 1172 startupinfo)
1173 finally:
1174 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~\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)
~\Anaconda3\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
250 svg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'svg', **kwargs))
251 if 'pdf' in formats:
--> 252 pdf_formatter.for_type(Figure, lambda fig: print_figure(fig, 'pdf', **kwargs))
253
254 #-----------------------------------------------------------------------------
~\Anaconda3\lib\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':
~\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs)
2047 orientation=orientation,
2048 dryrun=True,
-> 2049 **kwargs)
2050 renderer = self.figure._cachedRenderer
2051 bbox_artists = kwargs.pop("bbox_extra_artists", None)
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_pdf.py in print_pdf(self, filename, dpi, bbox_inches_restore, metadata, **kwargs)
2563 RendererPdf(file, dpi, height, width),
2564 bbox_inches_restore=bbox_inches_restore)
-> 2565 self.figure.draw(renderer)
2566 renderer.finalize()
2567 if not isinstance(filename, PdfPages):
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
1647
1648 mimage._draw_list_compositing_images(
-> 1649 renderer, self, artists, self.suppressComposite)
1650
1651 renderer.close_group('figure')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
2626 renderer.stop_rasterizing()
2627
-> 2628 mimage._draw_list_compositing_images(renderer, self, artists)
2629
2630 renderer.close_group('axes')
~\Anaconda3\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
136 if not_composite or not has_images:
137 for a in artists:
--> 138 a.draw(renderer)
139 else:
140 # Composite any adjacent images together
~\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
48 renderer.start_filter()
49
---> 50 return draw(artist, renderer, *args, **kwargs)
51 finally:
52 if artist.get_agg_filter() is not None:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in draw(self, renderer, *args, **kwargs)
1185 ticks_to_draw = self._update_ticks(renderer)
1186 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
-> 1187 renderer)
1188
1189 for tick in ticks_to_draw:
~\Anaconda3\lib\site-packages\matplotlib\axis.py in _get_tick_bboxes(self, ticks, renderer)
1123 for tick in ticks:
1124 if tick.label1On and tick.label1.get_visible():
-> 1125 extent = tick.label1.get_window_extent(renderer)
1126 ticklabelBoxes.append(extent)
1127 if tick.label2On and tick.label2.get_visible():
~\Anaconda3\lib\site-packages\matplotlib\text.py in get_window_extent(self, renderer, dpi)
928 raise RuntimeError('Cannot get window extent w/o renderer')
929
--> 930 bbox, info, descent = self._get_layout(self._renderer)
931 x, y = self.get_unitless_position()
932 x, y = self.get_transform().transform_point((x, y))
~\Anaconda3\lib\site-packages\matplotlib\text.py in _get_layout(self, renderer)
302 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
303 self._fontproperties,
--> 304 ismath=False)
305 offsety = (lp_h - lp_bl) * self._linespacing
306
~\Anaconda3\lib\site-packages\matplotlib\backends\backend_pdf.py in get_text_width_height_descent(self, s, prop, ismath)
2124 fontsize = prop.get_size_in_points()
2125 w, h, d = texmanager.get_text_width_height_descent(s, fontsize,
-> 2126 renderer=self)
2127 return w, h, d
2128
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in get_text_width_height_descent(self, tex, fontsize, renderer)
462 else:
463 # use dviread. It sometimes returns a wrong descent.
--> 464 dvifile = self.make_dvi(tex, fontsize)
465 with dviread.Dvi(dvifile, 72 * dpi_fraction) as dvi:
466 page = next(iter(dvi))
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in make_dvi(self, tex, fontsize)
326 self._run_checked_subprocess(
327 ["latex", "-interaction=nonstopmode", "--halt-on-error",
--> 328 texfile], tex)
329 for fname in glob.glob(basefile + '*'):
330 if not fname.endswith(('dvi', 'tex')):
~\Anaconda3\lib\site-packages\matplotlib\texmanager.py in _run_checked_subprocess(self, command, tex)
296 report = subprocess.check_output(command,
297 cwd=self.texcache,
--> 298 stderr=subprocess.STDOUT)
299 except subprocess.CalledProcessError as exc:
300 raise RuntimeError(
~\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
387
388 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 389 **kwargs).stdout
390
391
~\Anaconda3\lib\subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
464 kwargs['stderr'] = PIPE
465
--> 466 with Popen(*popenargs, **kwargs) as process:
467 try:
468 stdout, stderr = process.communicate(input, timeout=timeout)
~\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
767 c2pread, c2pwrite,
768 errread, errwrite,
--> 769 restore_signals, start_new_session)
770 except:
771 # Cleanup if the child failed starting.
~\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
1170 env,
1171 os.fspath(cwd) if cwd is not None else None,
-> 1172 startupinfo)
1173 finally:
1174 # Child is launched. Close the parent's copy of those pipe
FileNotFoundError: [WinError 2] The system cannot find the file specified
<Figure size 432x288 with 1 Axes>
Posts: 7,320
Threads: 123
Joined: Sep 2016
The code work when i test in Jupyter Notebook.
Try this,so for me plot.png get save in C:\\1_notebook.
A folder i have made to keep all notebooks.
import os
os.getcwd() Output: 'C:\\1_notebook'
|