Cannot save plot results created in matplotlib to a file in eps format

Asked 2 years ago, Updated 2 years ago, 93 views

import matplotlib.pylab as plt

x=np.array ([8,8**2,8**3,8**4,8**5,8**6])
y=np.array ([6.246, 26.0417, 97.0874, 340.909, 1166.67, 3870.97])
plt.plot(x,y)
plt.savefig("test.eps")

The above code says test.png, but if you change the extension to eps, it will not be saved and you will get the following error:

<ipython-input-23-eb636dd8cfff>in<module>
      4 y = np.array ([6.246, 26.0417, 97.0874, 340.909, 1166.67, 3870.97])
      5plt.plot(x,y)
---->6plt.savefig("test.eps")

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\pyplot.py in savefig(*args,**kwargs)
    687 def savefig (*args, **kwargs):
    688fig=gcf()
-->689res=fig.savefig(*args,**kwargs)
    690fig.canvas.draw_idle()#need this if'transparent=True' to reset colors
    691 return res

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\figure.py in savefig (self, fname, frameon, transparent, **kwargs)
   2092self.set_frameon (frameon)
   2093 
->2094self.canvas.print_figure(fname,**kwargs)
   2095 
   2096 if frameon:

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, box_inches, **kwargs)
   2073 orientation = orientation,
   2074bbox_inches_restore=_bbox_inches_restore,
->2075**kwargs)
   2076 finally:
   2077 if bbox_inches and restore_bbox:

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py imprint_eps (self, outfile, *args, **kwargs)
    919 
    920 def print_eps (self, outfile, *args, **kwargs):
-->921 return self._print_ps (outfile, 'eps', *args, **kwargs)
    922 
    923 def_print_ps(self, outfile, format, *args,

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py in_print_ps (self, outfile, format, papertype, dpi, facecolor, edgecolor, orientation, *args, **kwargs)
    944 self._print_figure_tex(outfile, format, dpi, facecolor, edgecolor,
    945 orientation, isLandscape, papertype,
-->946**kwargs)
    947 else:
    948self._print_figure(outfile, format, dpi, facecolor, edgecolor,

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py in_print_figure_tex (self, outfile, format, dpi, facecolor, edgecolor, orientation, isLandscape, papertype, metadata, dryrun, box_inches_restore) **
   1334 or rcParams ['text.usetex']):
   1335gs_distill(tmpfile, isEPSF, ptype=paperertype, bbox=bbox,
->1336 rotated=psfrag_rotated)
   1337 elifrcParams ['ps.usedistiller'] == 'xpdf':
   1338xpdf_distill(tmpfile, isEPSF, ptype=paperertype, bbox=bbox,

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py ings_distill(tmpfile, eps, ptype, bbox, rotated)
   1469 
   1470gs_exe = ps_backend_helper.gs_exe
->1471 ifps_backend_helper.support_ps2write:#gs version>=9
   1472 device_name = "ps2write"
   1473 else:

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py in supports_ps2write(self)
     92 True if the installed ghostscript supports ps2 write device.
     93         """
--- >94 return self.gs_version[0]>=9
     95 
     96 ps_backend_helper = PsBackendHelper()

C:\JuliaPkg\conda\3\lib\site-packages\matplotlib\backends\backend_ps.py ings_version(self)
     76 
     77s = subprocess.Popen(
--- >78 [self.gs_exe, "--version"], stdout=subprocess.PIPE)
     79         pipe, stderr = s.communicate()
     80         ver = pipe.decode('ascii')

C:\JuliaPkg\conda\3\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)
    707                                 c2pread, c2pwrite,
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         except:
    711             # Cleanup if the child failed starting.

C:\JuliaPkg\conda\3\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)
    995                                          env,
    996                                          os.fspath(cwd) if cwd is not None else None,
--> 997                                          startupinfo)
    998             finally:
    999                 # Child is launched. Close the parent's copy of those pipe

File Not the Founders Error :   [ Windows Error   2 ]   I can't find a file designated.

"It was written on another site, ""All you have to do is change the extension,"" but it didn't work and I couldn't decipher the contents of the error message well, so I asked for your help."

Thank you for your cooperation.

python python3 matplotlib

2022-09-30 21:40

1 Answers

When I was clattering with pip install from the command prompt, I was warned to upgrade pip, so I upgraded it and also

on jupyter.
import matplotlib.pylab as plt
import numpy as np
x = np.array ([1, 2, 3, 4, 5, 6])
y=np.array ([6.246, 26.0417, 97.0874, 340.909, 1166.67, 3870.97])
plt.plot(x,y)
plt.savefig("test.eps")

The eps file was generated.
It seems that the latest version was needed.Resolved.


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.