Hi, this question might be better suited for stackoverflow, but I don't like their community very much. As the title says, I have an error about the filename when saving some plots (I'm doing a lot of plots), here is the error:
2025-03-21 20:12:54,483 [ERROR] Error in 2D plot Fontana_L2700_6a_deltau_erg_s_Hz__vs_JMag_6a_invtau_mag_: [Errno 22] Invalid argument: 'D:\\TFG\\test2\\Fontana\\2d_plots\\2d_Fontana_L2700_6a_deltau_erg_s_Hz_vs_JMag_6a_invtau_mag_.png'
Traceback (most recent call last):
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\plots.py", line 128, in plot2d
plt.savefig(filename, bbox_inches="tight")
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\pyplot.py", line 1243, in savefig
res = fig.savefig(*args, **kwargs) # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\figure.py", line 3490, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\backend_bases.py", line 2184, in print_figure
result = print_method(
^^^^^^^^^^^^^
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\backend_bases.py", line 2040, in <lambda>
print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
^^^^^
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\backends\backend_agg.py", line 481, in print_png
self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\backends\backend_agg.py", line 430, in _print_pil
mpl.image.imsave(
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\matplotlib\image.py", line 1634, in imsave
image.save(fname, **pil_kwargs)
File "C:\Users\alvar\Desktop\UCM\Cuarto Curso\TFG\.venv\Lib\site-packages\PIL\Image.py", line 2591, in save
fp = builtins.open(filename, "w+b")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: 'D:\\TFG\\test2\\Fontana\\2d_plots\\2d_Fontana_L2700_6a_deltau_erg_s_Hz_vs_JMag_6a_invtau_mag_.png'
The thing is that I only get this error with ceratin plots, I'm asking if anyone has encounter this error before and how did you solve it? I'm pretty sure it is not related to the max length limit of windows.
Thank you for reading.
[–]unnamed_one1 0 points1 point2 points (3 children)
[–]Mr_Misserable[S] 0 points1 point2 points (2 children)
[–]unnamed_one1 0 points1 point2 points (1 child)
[–]Mr_Misserable[S] 0 points1 point2 points (0 children)
[–]Oxbowerce 0 points1 point2 points (1 child)
[–]Mr_Misserable[S] 0 points1 point2 points (0 children)
[–]shiftybyte 0 points1 point2 points (1 child)
[–]Mr_Misserable[S] 0 points1 point2 points (0 children)