Я пытаюсь сделать что-то вроде этого:
import seaborn as sns
import matplotlib.pyplot as plt
# edit me
fig, ax = plt.subplots(figsize=(9, 6))
tips = sns.load_dataset("tips")
#sns.stripplot(data=tips, x = ['f1','f2'], y=[combined_df.r1_feature1,combined_df.r2_feature1], hue = "size", palette = "deep")
# wide form with x,y missing
params_anno = dict(jitter=0.25, size=5, palette = "flare",
dodge=True)
if (value of df1 = value of df2):
params_anno["linewidth"].append(2)
params_anno["edgecolor"].append("green")
ax = sns.stripplot(data=combined_df.drop(
"cycle_number", axis=1), **params_anno)
ax.set_ylim([0, 25])
ax.set_xlabel(xlabel = "Different reads")
ax.set_ylabel(ylabel = "values")
Условие if должно определять, должны ли определенные точки или точки данных на sns.stripplot
выделяться цветом края, который выделяет их. Однако описанный выше подход потерпит неудачу, потому что после встречи с первым экземпляром True
все остальное впоследствии будет аннотировано.
Как мне это сделать? Я не знаю, насколько гибок sns.stripplot(data=combined_df)
, когда дело доходит до обработки каждой точки данных. ax.annotate
способ сделать это?
Я пытался использовать sns.stripplot
, но проблема заключается в доступе к каждой точке данных изолированно, поэтому ее можно пометить по-разному, если она соответствует условию if.
axes
.
import seaborn as sns
# load data
tips = sns.load_dataset("tips")
# separate the data by a condition
mask = tips.total_bill.gt(20)
gt20 = tips[mask]
lt20 = tips[~mask]
# plot the dataframes in separate stripplots
ax = sns.stripplot(x = "day", y = "total_bill", hue = "smoker", data=lt20, jitter=True, dodge=True)
sns.stripplot(x = "day", y = "total_bill", hue = "smoker", data=gt20, jitter=True, dodge=True, edgecolor='r', linewidth=1, legend=None, ax=ax)
# move the legend if needed
sns.move_legend(ax, bbox_to_anchor=(1, 1.02), loc='upper left')
'condition'
на основе условия и использовать его для hue=
.import seaborn as sns
# load data
tips = sns.load_dataset("tips")
# new column based on a condition
tips = tips.assign(condition=tips.total_bill.gt(20))
# plot the stripplot with hue set to the new column
ax = sns.stripplot(x = "day", y = "total_bill", hue = "condition", data=tips, jitter=True, dodge=True)
# move the legend
sns.move_legend(ax, bbox_to_anchor=(1, 1.02), loc='upper left')
dodge=False