Last active
March 27, 2024 07:21
-
-
Save partrita/6c752435d35c49e3193f13b127c5aac5 to your computer and use it in GitHub Desktop.
Dotplot with mean value with black bar.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib.pyplot as plt | |
| import pands as pd | |
| df = pd.read_csv("./data/230119_df_Bernard_Thienpont.csv") | |
| # CellType Sample SampleType Values | |
| # 0 NK_T 1 Tumor 0.007453 | |
| # 1 NK_T 4 Tumor 0.018171 | |
| # 2 NK_T 5 Tumor 0.052632 | |
| # 3 NK_T 6 Normal 0.151292 | |
| # 4 NK_T 8 Tumor 0.025943 | |
| # ... ... ... ... ... | |
| # 71 T_reg 20 Tumor 0.042694 | |
| # 72 T_reg 21 Tumor 0.019444 | |
| # 73 T_reg 22 Tumor 0.014368 | |
| # 74 T_reg 23 Tumor 0.023204 | |
| # 75 T_reg 24 Normal 0.023416 | |
| # 76 rows × 4 columns | |
| # Plotting | |
| data = df[df["CellType"] == "NK_T"] | |
| fig, ax = plt.subplots(figsize=(4, 6)) | |
| ax = sns.stripplot( | |
| x="SampleType", | |
| y="Values", | |
| # hue='SampleType', | |
| data=data, | |
| size=4, | |
| color=".7", | |
| ) | |
| # plt.xticks(rotation=45, ha="right") | |
| # p.set(yscale='log') | |
| # plot the mean line | |
| sns.boxplot( | |
| showmeans=True, | |
| meanline=True, | |
| meanprops={"color": "k", "ls": "-", "lw": 2}, | |
| medianprops={"visible": False}, | |
| whiskerprops={"visible": False}, | |
| zorder=10, | |
| x="SampleType", | |
| y="Values", | |
| # hue='SampleType', | |
| data=data, | |
| showfliers=False, | |
| showbox=False, | |
| showcaps=False, | |
| ax=ax, | |
| ) | |
| ax.set_ylabel("") | |
| ax.set_xlabel("NK T-cell") | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment