简体   繁体   English

Seaborn X 和 Y 散点图颜色

[英]Seaborn Scatterplot Color by X and Y

I am having trouble coloring what should be a simple scatter plot.我在着色应该是简单的散布 plot 时遇到问题。 I am plotting two comparing columns in my pandas data frame, but I would like to color the scatter plot by X scatter and by Y scatter.我正在我的 pandas 数据框中绘制两个比较列,但我想通过 X 散点图和 Y 散点图为散点 plot 着色。 So X scatter would be red and Y scatter will be black.所以 X 散点图是红色的,Y 散点图是黑色的。

Here is a snippet of what I have done so far.这是我到目前为止所做的一个片段。 This is with sns.lmplot, but I have tried with sns.scatterplot also.这是 sns.lmplot,但我也尝试过 sns.scatterplot。

fig, ax = plt.subplots(figsize=(10, 5))

x=df_layer10s2['xco2'].values
y=df_layer10s2['xco2_part'].values
col = (if x then 'r', else 'black')
ax= sns.lmplot(x='xco2',y='xco2_part',data=df_layer10s2)
# plt.ylim(389,404)
# plt.xlim(389,404)

also here is a image of how my dataframe is set up:这里还有一张我的 dataframe 是如何设置的图像:

在此处输入图像描述

I think you are confusing the parameters of lmplot .我认为您混淆了lmplot的参数。 Also, you could use regplot instead, as your not using the features that make lmplot different from regplot .此外,您可以改用regplot ,因为您没有使用使lmplot regplot的功能。 Regardless, it seems you should be using your 'time' column as your x-values and 'xco2' and 'xco2_part' as y-values.无论如何,您似乎应该使用'time'列作为 x 值,使用'xco2''xco2_part'作为 y 值。 In this case, you can make two plotting calls and set your color parameter.在这种情况下,您可以进行两次绘图调用并设置color参数。 So something like this:所以是这样的:

sns.regplot(x='time', y='xco2', data=df_layer10s2, color='r')
sns.regplot(x='time', y='xco2_part', data=df_layer10s2, color='k')

Here's an example:这是一个例子:

np.random.seed(42)
time = np.random.random(50)
y0 = np.random.random(50)
y1 = np.random.random(50)
df = pd.DataFrame({'time': time, 'y0': y0, 'y1': y1})

sns.regplot(x='time', y='y0', data=df, color='r')
sns.regplot(x='time', y='y1', data=df, color='k')

在此处输入图像描述

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

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