xxxxxxxxxx
x=['A','B','B','C','A','B']
y=[15,30,25,18,22,13]
# Function to map the colors as a list from the input list of x variables
def pltcolor(lst):
cols=[]
for l in lst:
if l=='A':
cols.append('red')
elif l=='B':
cols.append('blue')
else:
cols.append('green')
return cols
# Create the colors list using the function above
cols=pltcolor(x)
plt.scatter(x=x,y=y,s=500,c=cols) #Pass on the list created by the function here
plt.grid(True)
plt.show()
xxxxxxxxxx
from matplotlib import pyplot as plt
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [125, 32, 54, 253, 67, 87, 233, 56, 67]
color = [str(item/255.) for item in y]
plt.scatter(x, y, s=500, c=color)
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
population = np.random.rand(100)
Area = np.random.randint(100,600,100)
continent =['North America','Europe', 'Asia', 'Australia']*25
df = pd.DataFrame(dict(population=population, Area=Area, continent = continent))
fig, ax = plt.subplots()
colors = {'North America':'red', 'Europe':'green', 'Asia':'blue', 'Australia':'yellow'}
ax.scatter(df['population'], df['Area'], c=df['continent'].map(colors))
plt.show()
xxxxxxxxxx
import numpy as np
import matplotlib.pyplot as plt
# Generate data...
x = np.random.random(10)
y = np.random.random(10)
# Plot...
plt.scatter(x, y, c=y, s=500)
plt.gray()
plt.show()