0

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

3 Answers 3

2

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"])
Sign up to request clarification or add additional context in comments.

2 Comments

Ah perfect, lovely answer thanks mate. I did actually see that in the documentation but wasn't really sure what it meant as I couldn't see any examples. Thanks again mate.
There is an example using that argument at some point, but I agree it's not the best worked one.
2

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)

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.