Reputation: 772
df =
id_easy latitude longitude cluster
0 a1 45.1076 7.4920 0
0 b1 45.1064 7.5013 0
1 c1 44.9498 7.5010 1
1 d1 44.9656 7.5084 1
2 e1 45.0846 7.5277 2
2 f1 45.1650 7.7950 2
I want to visualize:
id_easy
a1
b1
of cluster
0
in different colors and the rest of the data grayid_easy
c1
d1
of cluster
1
in different colors and the rest of the data grayid_easy
e1
f1
of cluster
2
in different colors and the rest of the data grayI have this:
for index_in_red in df.index.unique():
my_dpi=96
plt.figure(figsize=(600/my_dpi, 400/my_dpi), dpi=my_dpi)
plt.plot(df.loc[df.index != index_in_red,'longitude'],df.loc[df.index != index_in_red,'latitude'] ,
color='silver', marker='o',linestyle='',linewidth=50, markersize=2)
plt.plot(df.loc[index_in_red,'longitude'],df.loc[index_in_red,'latitude'] ,
color='maroon',marker='o',linestyle='',linewidth=2, markersize=3)
plt.show()
But it gives me all values of id_easy
in maroon color, but I want them to be in different color
Desired output:
For every values of id_easy I have different color
Upvotes: 0
Views: 59
Reputation: 150735
This can be done with seaborn:
for cluster in df.cluster.unique():
# mask the cluster of interest
is_cluster = df.cluster.eq(cluster)
# plot the other clusters in gray
ax = df[~is_cluster].plot.scatter(x='latitude',y='longitude', c='gray')
# plot the cluster of interest in different colors
sns.scatterplot(data=df[is_cluster],
x='latitude',
y='longitude',
hue='id_easy',
ax=ax)
# you can do other stuff with ax here
# ax.set_title(...)...
plt.show()
At the end, you will have 3 plots:
Upvotes: 2
Reputation: 1130
Your question is not perfectly clear to me, is this what you are looking for?
in case this is the code I used:
df2=df.set_index('cluster')
fig, axs = plt.subplots(figsize=(10, 12), nrows=3,ncols=1,constrained_layout=True)
for clus in df2.index.unique():
axs[clus].plot(df2.latitude,df2.longitude,'o',color='grey',markersize=12)
axs[clus].plot(df2.loc[clus].latitude.iloc[0],df2.loc[clus].longitude.iloc[0],'o',markersize=12)
axs[clus].plot(df2.loc[clus].latitude.iloc[1],df2.loc[clus].longitude.iloc[1],'o',markersize=12)
axs[clus].set_xlabel('Latitude')
axs[clus].set_ylabel('Longitude')
axs[clus].set_title('Cluster '+str(clus))
Upvotes: 1