Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas scatter plot with different colors

rng = np.random.RandomState(0)
x = df['population']
y = df['Area']
colors = {'North America':'red', 'Europe':'green', 'Asia':'blue', 'Australia':'yellow'}

plt.scatter(x, y, s=100*df['population'], alpha=0.3,
            c= df['continent'].map(colors),
            cmap='viridis')
plt.colorbar();
Comment

pandas scatter plot with different colors

# Get Unique continents
color_labels = df['continent'].unique()

# List of colors in the color palettes
rgb_values = sns.color_palette("Set2", 4)

# Map continents to the colors
color_map = dict(zip(color_labels, rgb_values))

# Finally use the mapped values
plt.scatter(df['population'], df['Area'], c=df['continent'].map(color_map))
Comment

PREVIOUS NEXT
Code Example
Python :: python opencv open camera 
Python :: python create 2d array deep copy 
Python :: all column except pandas 
Python :: degrees to radians python 
Python :: get the system boot time in python 
Python :: remove whitespace in keys from dictionary 
Python :: how to find how many processors you have with python 
Python :: how to move a column in pandas dataframe 
Python :: delete turtle 
Python :: display result in same page using flask api 
Python :: loop through 2 dataframes at once 
Python :: comparing file content in python 
Python :: python continue vs pass 
Python :: python blowfish 
Python :: linux command on python 
Python :: python create folder if not exists 
Python :: how to get width of an object in pyqt5 
Python :: python nmap 
Python :: dot product python 
Python :: discordpy 
Python :: print random word py 
Python :: pygame mouse pos 
Python :: location of python in cmd 
Python :: python lowercase 
Python :: import fashion mnist keras 
Python :: Entry border color in tkinter 
Python :: python wikipedia api search 
Python :: cprofile usage python 
Python :: classes in python with self parameter 
Python :: python control browse mouse selenium 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =