Home > front end >  Is there any way that I assign a specific color to my node according to the value present in my list
Is there any way that I assign a specific color to my node according to the value present in my list

Time:12-24

Or you can say I applied clustering to my data and I want to assign a specific node color to that cluster.how can I do that?

I am unable to do so...please recommend me something.

CodePudding user response:

Yes, you can use a colormap to assign colors to your nodes based on the values present in your list.

Here is an example of how you can do this using the matplotlib library in Python:

import matplotlib.pyplot as plt
import matplotlib.cm as cm

# Create a scatter plot
plt.scatter(x, y, c=values, cmap=cm.viridis)

#Show the plot
plt.show()

In this example, x and y are the x- and y-coordinates of the nodes, values is a list of the values that you want to use to color the nodes, and cm.viridis is the colormap that you want to use. You can choose from a variety of colormaps available in matplotlib, or you can create your own custom colormap.

You can also use other libraries such as networkx to create and visualize graphs with colored nodes.

CodePudding user response:

Your question is quite unclear but if I understood correctly you can try putting your points with assigned clusters into pandas dataframe and then plot it with something like seaborn f.e.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.DataFrame({'X': [1,1,1.5,3,4],
                   'Y': [1.1, 1.3, 0.9, -2, -2.1],
                   'clusterId': [1,1,1,2,2]}) 
# Probably you want to start with only X, Y and generate clusterId in some way

fig, axes = plt.subplots(1,1)
sns.scatterplot(data=df,x='X', y='Y', hue='clusterId', ax=axes)
plt.show()

You can than also adjust colors markersizes styles etc. which you can find how to do in documentation or other stackoverflow questions

  • Related