I'm trying to plot a scatter plot with Matplotlib, but i'm having troubles setting colors.
Here is my code:
colors = [(141, 0, 248, 0.4) if x >= 150 and x < 200 else
(0, 244, 248, 0.4) if x >= 200 and x < 400 else
(255, 255, 0, 0.7) if x >= 400 and x < 600 else
(255, 140, 0, 0.8) if x >= 600 else (255, 0, 0, 0.8) for x in MyData.Qty]
print(len(colors))
ax1.scatter(MyData.Date, MyData.Rate, s=20, c=colors, marker='_')
Basically, i have a column called Qty on my dataframe, and according to that value, the colors is chosen. If Qty is bigger than x, the color will be red and so on, for example.
The previous code will give me the following error:
'c' argument has 2460 elements, which is inconsistent with 'x' and 'y' with size 615.
And i have no idea why does that happen, because if i try the following code, it will work without any problem:
colors = ['red' if x >= 150 and x < 200 else
'yellow' if x >= 200 and x < 400 else
'green' if x >= 400 and x < 600 else
'blue' if x >= 600 else 'purple' for x in MyData.Qty]
Here is a sample of my data:
Date Rate Qty
0 18 140 207.435145
0 18 141 155.019884
0 18 178 1222.215201
0 18 230 256.010358
0 19 9450 1211.310384
The following will work too:
colors = [(1,1,0,0.8) if x>1000 else (1,0,0,0.4) for x in MyData.Qty]