サブロウ丸

Sabrou-mal サブロウ丸

主にプログラミングと数学

【python】 matplotlib: color をRGB, RGBAで指定した際のwarning

matplotlibのplotやscatterでcolorを (0.0, 0.0, 0.803921568627451, 1.0) のようなRGBや, RGBAで指定した場合

plt.plot(..., c=(0.0, 0.0, 0.803921568627451, 1.0))

'c' argument looks like a single numeric RGB or RGBA sequence, which should be avoided as value-mapping will have precedence in case its length matches with 'x' & 'y'. Please use a 2-D array with a single row if you really want to specify the same RGB or RGBA value for all points.

というwarningが生じます.
document(https://matplotlib.org/3.1.3/api/_as_gen/matplotlib.axes.Axes.scatter.html)のnoteでは下記の記載がります。

Note that c should not be a single numeric RGB or RGBA sequence because that is indistinguishable from an array of values to be colormapped. If you want to specify the same RGB or RGBA value for all points, use a 2-D array with a single row. Otherwise, value- matching will have precedence in case of a size matching with x and y.

colormapの値と混合するので, その入力の仕方はやめてねということです. 対処法は上記の通り cに長さ1のリストにして渡してやればよいです.

plt.plot(..., c=[(0.0, 0.0, 0.803921568627451, 1.0)])

これでok.