Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to plot labeled data with different colors

import matplotlib
import matplotlib.pyplot as plt
import numpy as np

x = [4,8,12,16,1,4,9,16]
y = [1,4,9,16,4,8,12,3]
label = [0,1,2,3,0,1,2,3]
colors = ['red','green','blue','purple']

fig = plt.figure(figsize=(8,8))
plt.scatter(x, y, c=label, cmap=matplotlib.colors.ListedColormap(colors))

cb = plt.colorbar()
loc = np.arange(0,max(label),max(label)/float(len(colors)))
cb.set_ticks(loc)
cb.set_ticklabels(colors)
Comment

PREVIOUS NEXT
Code Example
Python :: python package for misspelled words 
Python :: dijkstras python 
Python :: How to know size of Python list 
Python :: how to read panda column 
Python :: assign a same value to 2 variables at once python 
Python :: pandas nan values in column 
Python :: python turtle jupyter notebook 
Python :: count consecutive values in python 
Python :: argparse cli 
Python :: regex remove all html tags except br python 
Python :: python iterating through a string 
Python :: time.strftime("%H:%M:%S") in python 
Python :: open tar file pandas 
Python :: shell script to run python 
Python :: Error: The file/path provided (flaskr) does not appear to exist. Please verify the path is correct. If app is not on PYTHONPATH, ensure the extension is .py 
Python :: python use functions from another file 
Python :: get last 3 in list python 
Python :: how to merge two pandas dataframes on a column 
Python :: python string contains 
Python :: from collections import defaultdict 
Python :: django model form 
Python :: python web crawler 
Python :: torch flatten 
Python :: import picturein colab 
Python :: python list all but first 
Python :: python winsound 
Python :: connect mysql sql alchemy 
Python :: django get fields data from object model 
Python :: python sum of list axes 
Python :: python positional argument follows keyword argument 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =