top bantz
top bantz

Reputation: 615

Specifying data to plot in Seaborn pairplot

I really like using Seaborn's PairPlot chart/function, but I wondered if there was a way to be a bit more specific about what plots to see.

For example, I have a df of stock prices. Let's say Stock A, Stock B, Stock C, Stock D etc.

Using sns.pairplot(df) I get the following:

enter image description here

What I would like to do is be able to plot for example, Stock A, Stock B, Stock C, against Stock X, Stock Y, Stock Z. SO A, B and C will appear along the X-axis, and X, Y and Z will appear along the Y-axis. This will of course result in to bar charts.

And as an extra point if anyone knows how I can display the line of best fit along with the r-squared number on each plot that would be amazing.

Cheers

Upvotes: 0

Views: 1463

Answers (3)

Sam Mason
Sam Mason

Reputation: 16184

you can use seaborn's PairGrid to do regression plots. something like this should work:

g = sns.PairGrid(
    df,
    x_vars=["Stock A", "Stock B", "Stock C"],
    y_vars=["Stock X", "Stock Y", "Stock Z"]
)
g.map(sns.regplot)

Upvotes: 2

P.hunter
P.hunter

Reputation: 1365

for bar graph:

sns.barplot(x=["Stock A", "Stock B", "Stock C"], y=["Stock X", "Stock Y", "Stock Z"], data=your_data)

for the latter you might wanna look at: https://seaborn.pydata.org/generated/seaborn.regplot.html

Upvotes: 1

Ignacio Vergara Kausel
Ignacio Vergara Kausel

Reputation: 5996

Using x_varsand y_vars indicating which columns you want see. pairplot documentation

sns.pairplot(df, x_vars=["Stock A", "Stock B", "Stock C"], y_vars=["Stock X", "Stock Y", "Stock Z"])

Upvotes: 2

Related Questions