【问题标题】:pandas seaborn pointplot normalized by control group mean由对照组均值归一化的 pandas seaborn pointplot
【发布时间】:2021-11-04 04:31:50
【问题描述】:

我正在努力寻找一种解决方案来规范化 pandas 数据帧的分组 seaborn 点图通过对照组

为了更清楚,这是我的 seaborn 情节的结果 , 由于这段代码:

sns.pointplot(x='CELL TYPE',y='VELOCITY', hue = 'condition',ci=99 ,data=df_condition_cut1,ax = ax,order=['FRONT', 'MIDDLE', 'BACK'],
                               ordered=True)

我想要获得的是这种图,但通过每个条件下的 FRONT 单元类型的平均值进行归一化。

请在此处找到带有简化图的重要采样数据集

from matplotlib import pyplot as plt 
import seaborn as sns
import pandas as pd

df_cells = pd.DataFrame(data = {'VELOCITY':[1.4,1.6,1.3,1.1,0.8,0.7,2.3,1.8,1.7,1.5,1.6,1.7],
                         'condition':['A1','A1','A1','A1','A1','A1','A2','A2','A2','A2','A2','A2'],
                         'CELL TYPE':['FRONT','FRONT','MIDDLE','MIDDLE','BACK','BACK','FRONT','FRONT','MIDDLE','MIDDLE','BACK','BACK']})
print(df_cells)
fig, ax = plt.subplots(figsize=(25,12))
sns.pointplot(x='CELL TYPE',y='VELOCITY', hue = 'condition',ci=99 ,data=df_cells,ax = ax,order=['FRONT', 'MIDDLE', 'BACK'],
                                   ordered=True)

你对如何获得这个有什么建议吗?

谢谢 伊曼纽尔

【问题讨论】:

  • 请问,您能否提供大量数据样本?
  • 亲爱的@Zephyr,我已经用采样数据更新了我的帖子,并进行了一些剪裁以绘制它

标签: python pandas plot seaborn


【解决方案1】:

感谢这篇文章

https://stackoverflow.com/a/55971778/15416347

我找到了解决办法。

在我的特定情况下,此代码有效:

t2=df_cells.loc[df_cells['CELL TYPE']=='FRONT',['VELOCITY','CELL TYPE','condition']].groupby('condition').VELOCITY.mean()
df_cells['VELOCITY_norm']=df_cells.VELOCITY/t2.reindex(df_cells.condition).values

df_cells.VELOCITY_norm
fig, ax = plt.subplots(figsize=(25,12))
sns.pointplot(x='CELL TYPE',y='VELOCITY_norm', hue = 'condition',ci=99 ,data=df_cells,ax = ax,order=['FRONT', 'MIDDLE', 'BACK'],
                                   ordered=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    • 2017-03-03
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多