Python 3.x seaborn:stripplot如何基于值为单个点着色
我试图根据定义的值为seaborn:stripplot上的特定点上色。比如说,Python 3.x seaborn:stripplot如何基于值为单个点着色,python-3.x,pandas,matplotlib,seaborn,Python 3.x,Pandas,Matplotlib,Seaborn,我试图根据定义的值为seaborn:stripplot上的特定点上色。比如说, value=(df['x']=0.0 我知道您可以使用regplot等进行此操作: df['color']=np.where(value==True,“#9b59b6”)和 scatter_kws={'facecolors':df['color']} 对于对网格和条带图,是否有方法进行此操作?具体来说,在下面的t1或t2中为指定值上色 我还尝试在hue中传递matchvar。但是,这生成了下面的图像#2,而不是我想要
value=(df['x']=0.0
我知道您可以使用regplot等进行此操作:
df['color']=np.where(value==True,“#9b59b6”)
和
scatter_kws={'facecolors':df['color']}
对于对网格
和条带图
,是否有方法进行此操作?具体来说,在下面的t1
或t2
中为指定值上色
我还尝试在hue
中传递match
var。但是,这生成了下面的图像#2,而不是我想要的
这是df
:
par t1 t2 found
30000.0 0.50 0.45 yes
10000.0 0.30 0.12 yes
3000.0 0.40 0.00 no
这是我的密码:
# Import dependencies
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv("data.csv")
# Make the PairGrid
g = sns.PairGrid(df.sort_values("par", ascending=True),
x_vars=df.columns[1:3], y_vars=["par"],
height=5, aspect=.65)
# Draw a dot plot using the stripplot function
g.map(sns.stripplot, size=16, orient="h",
linewidth=1, edgecolor="gray", palette="ch:2.5,-.2,dark=.3")
sns.set_style("darkgrid")
# Use the same x axis limits on all columns and add better labels
g.set(xlim=(-0.1, 1.1), xlabel="% AF", ylabel="")
# Use semantically meaningful titles for the columns
titles = ["Test 1", "Test 2"]
for ax, title in zip(g.axes.flat, titles):
# Set a different title for each axes
ax.set(title=title)
# Make the grid horizontal instead of vertical
ax.xaxis.grid(False)
ax.yaxis.grid(True)
sns.despine(left=True, bottom=True)
我正在尝试使用值=0.0
不同的颜色为点上色:
将match
var传递到hue
生成以下值,并删除第三个par=3000
值,并折叠绘图。我可以对我希望以不同颜色突出显示的异常值进行分类。但是,从y轴删除异常值,并折叠绘图
你确定想要一个
条带图吗?在我看来,你实际上是在试图绘制一个散点图
此外,我认为您希望使用FacetGrid
而不是PairGrid
?在这种情况下,需要以“长格式”转换数据帧
以下是我得到的:
df2 = df.melt(id_vars=['par','found'], var_name='Test', value_name='AF')
g = sns.FacetGrid(data=df2, col='Test', col_order=['t1','t2'], hue='found',
height=5, aspect=.65)
g.map(sns.scatterplot, 'AF','par',
s=100, linewidth=1, edgecolor="gray", palette="ch:2.5,-.2,dark=.3")
你确定想要一个条带图吗?在我看来,你实际上是在试图绘制一个散点图
此外,我认为您希望使用FacetGrid
而不是PairGrid
?在这种情况下,需要以“长格式”转换数据帧
以下是我得到的:
df2 = df.melt(id_vars=['par','found'], var_name='Test', value_name='AF')
g = sns.FacetGrid(data=df2, col='Test', col_order=['t1','t2'], hue='found',
height=5, aspect=.65)
g.map(sns.scatterplot, 'AF','par',
s=100, linewidth=1, edgecolor="gray", palette="ch:2.5,-.2,dark=.3")