【问题标题】:Invalid RGBA color "ro" in matplotlib while using the plot() function使用 plot() 函数时 matplotlib 中的 RGBA 颜色“ro”无效
【发布时间】:2020-06-10 22:35:02
【问题描述】:

我一直在尝试使用 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'

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

0.5766199490353112
1648.0609161647387

有什么方法可以找出问题所在吗?我正在使用 tkinter 和 matplotlib

【问题讨论】:

    标签: python 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')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-15
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-13
      相关资源
      最近更新 更多