[python] Python matplotlib showing different colours in scatterplot

Viewer

copydownloadembedprintName: Python matplotlib showing different colours in scatterplot
  1. import matplotlib.pyplot as plt
  2. import random
  3. import numpy
  4. pcolors = numpy.array(['#FF0000', '#C400FF', '#0000FF', '#00C4FF', '#00FF5E'])
  5. vendors = {'ibm':0,'wipro':1,'tcs':2}
  6. cats = {'a','b'}
  7.  
  8. for v in vendors:
  9.     pol  = [x*0.5 + random.randint(0,3) for x in range(0,5)]
  10.     sub  = [x*0.5 + random.randint(0,3) for x in range(0,5)]    
  11.     for i,in enumerate(cats):
  12.         """ """
  13.         #plt.scatter(pol,sub,s=60)              # shows different colors
  14.         plt.scatter(pol,sub,s=60,c=pcolors)  # shows only 1 color
  15. plt.show()

Editor

You can edit this paste and save as new:


File Description
  • Python matplotlib showing different colours in scatterplot
  • Paste Code
  • 22 May-2022
  • 549 Bytes
You can Share it: