简体   繁体   English

指定要在Seaborn对图中绘制的数据

[英]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. 我真的很喜欢使用Seaborn的PairPlot图表/函数,但我想知道是否有一种方法可以更具体地了解要查看的图。

For example, I have a df of stock prices. 例如,我有一个df的股票价格。 Let's say Stock A , Stock B , Stock C , Stock D etc. 假设Stock AStock BStock CStock D等。

Using sns.pairplot(df) I get the following: 使用sns.pairplot(df)我得到以下信息:

在此处输入图片说明

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 . 我想做的是能够绘制例如Stock AStock BStock CStock XStock YStock Z图表。 SO A, B and C will appear along the X-axis, and X, Y and Z will appear along the Y-axis. SO A,B和C将沿X轴显示,X,Y和Z将沿Y轴显示。 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. 另外要点是,如果有人知道我如何在每个图上显示最佳拟合线以及r平方数,那将是惊人的。

Cheers 干杯

you can use seaborn's PairGrid to do regression plots . 您可以使用seaborn的PairGrid进行回归图 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)

Using x_vars and y_vars indicating which columns you want see. 使用x_varsy_vars指示要查看的列。 pairplot documentation 对图文档

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

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 对于后者,您可能想看看: https : //seaborn.pydata.org/genic/seaborn.regplot.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM