提问者:小点点

使用plot()函数时,matplotlib中的RGBA颜色“ro”无效


我一直在尝试使用matplotlib中的figure.figure.plot()函数

figplot = fig.add_subplot(111)
print(lines[2].get_xdata()[0])
print(lines[2].get_ydata()[0])
figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], c='ro')

但在尝试执行此操作时,我会收到以下错误消息:

Traceback (most recent call last):
  File "/usr/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
    return self.func(*args)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/_backend_tk.py", line 259, in resize
    self.draw()
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 9, in draw
    super(FigureCanvasTkAgg, self).draw()
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/figure.py", line 1709, in draw
    renderer, self, artists, self.suppressComposite)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/axes/_base.py", line 2647, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/image.py", line 135, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/lines.py", line 783, in draw
    lc_rgba = mcolors.to_rgba(self._color, self._alpha)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py", line 177, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/usr/local/lib/python3.7/dist-packages/matplotlib/colors.py", line 233, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 'ro'

我注意到对于散点图,颜色必须是一个数组,但这不是散点图。 行[2].get_xData()[0]行[2].get_yData()[0]的值如下:

0.5766199490353112
1648.0609161647387

有什么办法能查出出了什么问题吗? 我正在使用tkinter和matplotlib


共1个答案

匿名用户

RO是颜色标记代码。 您应该删除C=:

figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], 'ro')

或者可以指定颜色而不使用标记o:

figplot.plot(lines[2].get_xdata()[0], lines[2].get_ydata()[0], c='r')