Cy Bu
Cy Bu

Reputation: 1437

Matplotlib warning using pandas.DataFrame.plot.scatter()

One windows 10, with versions: Python 3.5.2, pandas 0.23.4, matplotlib 3.0.0, numpy 1.15.2, the following code give me the following warning that i would like to sort out

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.cm as cm

# a 5x4 random pandas DataFrame
pf = pd.DataFrame(np.random.random((5,4)), columns=['a', 'b', 'c', 'd'])

# colors: 
colors = cm.rainbow(np.linspace(0, 1, 4))

fig1 = pf.plot.scatter('a', 'b', color='k')
for i, j in enumerate(['b', 'c', 'd']):
    pf.plot.scatter('a', j, color=colors[i+1], ax = fig1)

And I get a warning:

'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.

Could you point me on how to address that warning?

Upvotes: 3

Views: 2311

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339350

I can't reproduce the warning with matplotlib 3.0 and pandas 0.23.4, but what it says is essentially that you should not use a single RGB tuple to specify a color.

So instead of color=colors[i+1] use

color=[colors[i+1]]

Upvotes: 8

Related Questions