0

What I tried

# import libraries
from matplotlib import pyplot as plt
import numpy as np
import seaborn as sns
import pandas as pd

# function for plotting data
def plot_data(data):
    X_1 = data["x1"]
    X_2 = data["x2"]
    Y = data["y"]

    # Create data frame with randomly selected x and y positions
    df = pd.DataFrame(data = data, columns=["x1","x2"])
    

    # Add a column: the color depends on x1 and x2 values.
    value = (df["x1"] <= 7) & (df["x1"] > 0)
    df['color']= np.where( value==True , "#9b59b8", "#3498db")

    # plot
    sns.regplot(data=df, x="x1", y="x2", fit_reg=False, scatter_kws= 
                {'facecolors':df['color']})



    plt.title("Datasets for Neural network")
    plt.xlabel("X_1")
    plt.ylabel("X_2")

    plt.show()

data = pd.read_csv('./assets/data/data0/data.csv')
plot_data(data)

Output

enter image description here

This is not the output I want. I want two different colors for two different clusters of data. enter image description here

Data on the left needs to be in purple and on right it should be in blue.

My dataset in CSV

y,x1,x2

1.0000,2.6487,4.5192

1.0000,1.5438,2.4443

1.0000,1.8990,4.2409

1.0000,2.4711,5.8097

1.0000,3.3590,6.4423

1.0000,3.2406,5.8097

1.0000,3.8128,6.3917

1.0000,4.4441,6.8725

1.0000,3.6747,6.7966

Resources I tried

StackOverflow q/a, didn't resolve my problem

Took help from this site. But, does not resolve my problem when I want to plot features x1 vs x2 and want the different color for the different cluster.

How could I do that?

F.C. Akhi
  • 181
  • 1
  • 10
  • 4
    You set a different color if `x1 <7`, while you want a different color if `x1 < x2`. Does the following give the desired result? `value = (df["x1"] <= df["x2"])` – dkruit Sep 30 '22 at 08:55
  • @dkruit Thank you for pointing out the error I was making in writing conditions. It works! – F.C. Akhi Sep 30 '22 at 09:04
  • As the issue is resolved by adjusting the existing comparison line in the code, I'm voting to close the question as caused by a typo / not reproducible. – Trenton McKinney Sep 30 '22 at 14:57

0 Answers0