9
votes

I'm using python 2.7. I know this will be very basic, however I'm really confused and I would like to have a better understanding of seaborn.

I have two numpy arrays X and y and I'd like to use Seaborn to plot them.

Here is my X numpy array:

[[ 1.82716998 -1.75449225]
 [ 0.09258069  0.16245259]
 [ 1.09240926  0.08617436]]

And here is the y numpy array:

[ 1. -1.  1. ]

How can I successfully plot my data points taking into account the class label from the y array?

Thank you,

1
Can you also add how you want the X & Y to be correlated and what X means? X array has shape of 2 x 3 values. These 2 things in array are x, y coordinates? How to display the Y values? Would you like a scatter plot? - devssh

1 Answers

7
votes

You can use seaborn functions to plot graphs. Do dir(sns) to see all the plots. Here is your output in sns.scatterplot. You can check the api docs here or example code with plots here

import seaborn as sns 
import pandas as pd

df = pd.DataFrame([[ 1.82716998, -1.75449225],
 [ 0.09258069,  0.16245259],
 [ 1.09240926,  0.08617436]], columns=["x", "y"])

df["val"] = pd.Series([1, -1, 1]).apply(lambda x: "red" if x==1 else "blue")


sns.scatterplot(df["x"], df["y"], c=df["val"]).plot()

Gives

enter image description here Is this the exact input output you wanted?

You can do it with pyplot, just importing seaborn changes pyplot color and plot scheme

import seaborn as sns 

import matplotlib.pyplot as plt
fig, ax = plt.subplots()

df = pd.DataFrame([[ 1.82716998, -1.75449225],
 [ 0.09258069,  0.16245259],
 [ 1.09240926,  0.08617436]], columns=["x", "y"])
df["val"] = pd.Series([1, -1, 1]).apply(lambda x: "red" if x==1 else "blue")
ax.scatter(x=df["x"], y=df["y"], c=df["val"])
plt.plot()

Here is a stackoverflow post of doing the same with sns.lmplot