前提・実現したいこと
複数のデータを重ね書きしてグラフ化し、画像として出力したい。
x,yは辞書型でx[1]とy[1],x[2]とy[2],,,と重ね書きしたグラフの画像出力ができず困っています。
発生している問題・エラーメッセージ
python
1--------------------------------------------------------------------------- 2FileNotFoundError Traceback (most recent call last) 3<ipython-input-58-5b5d31b0ab22> in <module> 4 20 plt.rcParams['axes.linewidth'] = 1.0 5 21 plt.figure(figsize=(6.28,3.8)) 6---> 22 plt.savefig(str(fn)+'selfdischarge.png',transparent=True, dpi=300) 7~\anaconda3\lib\site-packages\matplotlib\pyplot.py in savefig(*args, **kwargs) 8 727 def savefig(*args, **kwargs): 9 728 fig = gcf() 10--> 729 res = fig.savefig(*args, **kwargs) 11 730 fig.canvas.draw_idle() # need this if 'transparent=True' to reset colors 12 731 return res 13 14~\anaconda3\lib\site-packages\matplotlib\figure.py in savefig(self, fname, transparent, **kwargs) 15 2178 self.patch.set_visible(frameon) 16 2179 17-> 2180 self.canvas.print_figure(fname, **kwargs) 18 2181 19 2182 if frameon: 20 21~\anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, **kwargs) 22 2089 orientation=orientation, 23 2090 bbox_inches_restore=_bbox_inches_restore, 24-> 2091 **kwargs) 25 2092 finally: 26 2093 if bbox_inches and restore_bbox: 27 28~\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, metadata, pil_kwargs, *args, **kwargs) 29 528 renderer = self.get_renderer() 30 529 with cbook._setattr_cm(renderer, dpi=self.figure.dpi), \ 31--> 530 cbook.open_file_cm(filename_or_obj, "wb") as fh: 32 531 _png.write_png(renderer._renderer, fh, 33 532 self.figure.dpi, metadata=metadata) 34 35~\anaconda3\lib\contextlib.py in __enter__(self) 36 110 del self.args, self.kwds, self.func 37 111 try: 38--> 112 return next(self.gen) 39 113 except StopIteration: 40 114 raise RuntimeError("generator didn't yield") from None 41 42~\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in open_file_cm(path_or_file, mode, encoding) 43 445 def open_file_cm(path_or_file, mode="r", encoding=None): 44 446 r"""Pass through file objects and context-manage `.PathLike`\s.""" 45--> 447 fh, opened = to_filehandle(path_or_file, mode, True, encoding) 46 448 if opened: 47 449 with fh: 48 49~\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in to_filehandle(fname, flag, return_opened, encoding) 50 430 fh = bz2.BZ2File(fname, flag) 51 431 else: 52--> 432 fh = open(fname, flag, encoding=encoding) 53 433 opened = True 54 434 elif hasattr(fname, 'seek'): 55 56FileNotFoundError: [Errno 2] No such file or directory: "{1: '20210318_LIC321_wood_self_remain.csv2.csv', 2: '20210318_LIC322_maxsorb30_self_remain.csv2.csv', 3: '20210317_LIC_maxsorb30_2000_self_remain.csv2.csv', 4: '20210317_LIC319_maxsobr30_2400_self_remain.csv2.csv'}selfdischarge.png" 57 58
該当のソースコード
python
1x = dict() 2y = dict() 3for i in range(1,5): 4 x[i] = df[i]['TIME'] 5 y[i] = df[i]['V'] 6plt.plot(x[1],y[1], color = 'red',linewidth = 1, linestyle='solid') 7plt.plot(x[2],y[2], color = 'blue',linewidth = 1, linestyle='solid') 8plt.plot(x[3],y[3], color = 'black',linewidth = 1, linestyle='solid') 9plt.plot(x[4],y[4], color = 'green',linewidth = 1, linestyle='solid') 10plt.xlim(0,25) 11plt.ylim(0,1) 12plt.ylabel('Potential (V vs.Li$^{+}$/Li)') 13plt.xlabel('Time (hour)') 14plt.rcParams['font.family'] ='Arial' 15plt.rcParams['xtick.direction'] = 'in' 16plt.rcParams['ytick.direction'] = 'in' 17plt.rcParams['xtick.major.width'] = 1.0 18plt.rcParams['ytick.major.width'] = 1.0 19plt.rcParams['font.size'] = 15 20plt.rcParams['axes.linewidth'] = 1.0 21plt.figure(figsize=(6.28,3.8)) 22plt.savefig(str(fn)+'selfdischarge.png',transparent=True, dpi=300)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/04/09 21:47