Home > database >  Scatter Problem : ValueError: 'c' argument has 2 elements, which is inconsistent with 
Scatter Problem : ValueError: 'c' argument has 2 elements, which is inconsistent with 

Time:10-14

I hope you're doing well. I am making a scatter chart using matplotlib in python and want that scatter points of X and Y axis have different colors. I am giving an array to it but for some reason it is giving error.

Scatter Problem : ValueError: 'c' argument has 2 elements, which is inconsistent with 'x' and 'y' with size 70120

Here's my code

import matplotlib.pyplot as plt
import pandas as pd

#Reading The Data
soc_data = pd.read_csv('research/featurespace/optical_sar.csv')
print(soc_data.columns)

# Axis Data
x = soc_data.SOCOptical
y = soc_data.SOCSAR

#plotting
plt.scatter(x,y,s=0.001,color=['green','yellow'])
plt.title('2D Feature Space - SOC Optical v/s SOC SAR')
plt.xlabel('Optical Predicted SOC')
plt.ylabel('SAR Predicted SOC')
plt.show()

When I remove the color property this chart is displayed.

enter image description here

Kindly help me.

CodePudding user response:

Of course, the parameter "color" must match the size of X and Y.

The solution here is to give to the parameter "color" a list of strings, indicating which color must be associated with every point.

So you need to give a list of 70120 strings.

  • Related