Cluster Analysis in Python
Shaumik Daityari
Business Analyst
seaborn
: a Python data visualization library based on matplotlib
hue
parameter for plotsfrom matplotlib import pyplot as plt
df = pd.DataFrame({'x': [2, 3, 5, 6, 2], 'y': [1, 1, 5, 5, 2], 'labels': ['A', 'A', 'B', 'B', 'A']})
colors = {'A':'red', 'B':'blue'}
df.plot.scatter(x='x', y='y', c=df['labels'].apply(lambda x: colors[x])) plt.show()
from matplotlib import pyplot as plt
import seaborn as sns
df = pd.DataFrame({'x': [2, 3, 5, 6, 2], 'y': [1, 1, 5, 5, 2], 'labels': ['A', 'A', 'B', 'B', 'A']})
sns.scatterplot(x='x', y='y', hue='labels', data=df) plt.show()
Cluster Analysis in Python