求助,python使用matplotlib画子图颜色,修改多个颜色报错

求助,python使用matplotlib画子图颜色,修改多个颜色报错

使用python,用pandas读取数据,matplotlib画2行1列的子图,想要给两个子图中的线条设置颜色(每个子图有三条线)

遇到问题,代码和报错如下

代码如下

fig = plt.figure()
ax1 = fig.add_subplot(211)
ax1.plot(df['采集时间'],df[['1','2','3']],linewidth = 2,marker = '.',color = ['r','g','b'])
ax1.set_title('走势图1')
plt.xticks(range(0,len(data),4))
ax1.set_xticklabels(data[::4])
ax2 = fig.add_subplot(212)
ax2.plot(df['采集时间'],df[['4','5','6']],linewidth = 2,marker = '.',color = ['r','g','b'])
ax2.set_title('走势图2')
plt.xticks(range(0,len(data),4))
ax2.set_xticklabels(data[::4])
plt.rcParams['font.sans-serif']=['SimHei'] # 显示中文标签
plt.subplots_adjust(hspace = 0.4) # 设置两个图之间的间距

报错如下:

File "g:/Python/绘图测试.py", line 32, in <module>

plt.savefig(buffer)  

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibpyplot.py", line 722, in savefig

res = fig.savefig(*args, **kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibfigure.py", line 2180, in savefig

self.canvas.print_figure(fname, **kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibbackend_bases.py", line 2082, in
print_figure

**kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibbackendsbackend_agg.py", line 527, in print_png

FigureCanvasAgg.draw(self)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibbackendsbackend_agg.py", line 388, in draw

self.figure.draw(self.renderer)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibartist.py", line 38, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibfigure.py", line 1709, in draw

renderer, self, artists, self.suppressComposite)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibimage.py", line 135, in _draw_list_compositing_images

a.draw(renderer)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibartist.py", line 38, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibaxes_base.py", line 2647, in draw

mimage._draw_list_compositing_images(renderer, self, artists)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibimage.py", line 135, in _draw_list_compositing_images

a.draw(renderer)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibartist.py", line 38, in draw_wrapper

return draw(artist, renderer, *args, **kwargs)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotliblines.py", line 783, in draw

lc_rgba = mcolors.to_rgba(self._color, self._alpha)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibcolors.py", line 177, in to_rgba

rgba = _to_rgba_no_colorcycle(c, alpha)

File "C:UsersAdministratorAppDataLocalProgramsPythonPython36libsite-packagesmatplotlibcolors.py", line 240, in _to_rgba_no_colorcycle

raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))

ValueError: Invalid RGBA argument: ['r', 'g', 'b']

以上是 求助,python使用matplotlib画子图颜色,修改多个颜色报错 的全部内容, 来源链接: utcz.com/a/157324.html

回到顶部