Skip to content

Instantly share code, notes, and snippets.

@partrita
Created March 27, 2024 06:06
Show Gist options
  • Select an option

  • Save partrita/93a8076df96f37267de3c01c12295970 to your computer and use it in GitHub Desktop.

Select an option

Save partrita/93a8076df96f37267de3c01c12295970 to your computer and use it in GitHub Desktop.
Simple matplotlib errorbar plot/
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("./data/230116_Tumor_regression.csv")
# Group Mouse Day Tumor(mm2)
# 0 G1 2210ES50_1 0 0.000000
# 1 G1 2210ES50_1 7 107.827200
# 2 G1 2210ES50_1 11 674.233875
# 3 G1 2210ES50_1 14 1573.768326
# 4 G1 2210ES50_1 18 3341.605256
# 5 G1 2210ES50_1 21 NaN
# 6 G1 2210ES50_1 25 NaN
# 7 G1 2210ES50_2 0 0.000000
# 8 G1 2210ES50_2 7 100.800000
# 9 G1 2210ES50_2 11 496.716748
# 10 G1 2210ES50_2 14 841.555000
# 11 G1 2210ES50_2 18 1405.689022
# 12 G1 2210ES50_2 21 2646.805230
# 13 G1 2210ES50_2 25 5637.610768
# 14 G1 2210ES50_3 0 0.000000
# 15 G1 2210ES50_3 7 107.681959
# 16 G1 2210ES50_3 11 500.273193
# 17 G1 2210ES50_3 14 1124.932500
# 18 G1 2210ES50_3 18 2096.455680
# 19 G1 2210ES50_3 21 3191.421303
# 20 G1 2210ES50_3 25 NaN
# 21 G4 2210ES50_22 0 0.000000
# 22 G4 2210ES50_22 7 109.263302
# 23 G4 2210ES50_22 11 162.636750
# 24 G4 2210ES50_22 14 429.359329
# 25 G4 2210ES50_22 18 720.147825
# 26 G4 2210ES50_22 21 1906.932632
# 27 G4 2210ES50_22 25 3553.364896
# 28 G4 2210ES50_23 0 0.000000
# 29 G4 2210ES50_23 7 102.136645
# 30 G4 2210ES50_23 11 305.984322
# 31 G4 2210ES50_23 14 445.383615
# 32 G4 2210ES50_23 18 1233.813600
# 33 G4 2210ES50_23 21 1877.068432
# 34 G4 2210ES50_23 25 3941.033324
# 35 G4 2210ES50_24 0 0.000000
# 36 G4 2210ES50_25 7 116.458545
# 37 G4 2210ES50_26 11 218.484000
# 38 G4 2210ES50_27 14 299.380752
# 39 G4 2210ES50_28 18 1230.631529
# 40 G4 2210ES50_29 21 2177.525467
# 41 G4 2210ES50_30 25 3898.437944
df_pivot = pd.pivot_table(
df,
index=["Group", "Day"],
# columns = 'Day',
values="Tumor(mm2)",
aggfunc=[np.mean, np.std],
)
x = df_pivot.loc["G1"].index
y1 = df_pivot.loc["G1", "mean"].values.flatten()
y2 = df_pivot.loc["G4", "mean"].values.flatten()
yerr1 = df_pivot.loc["G1", "std"].values.flatten()
yerr2 = df_pivot.loc["G4", "std"].values.flatten()
# np.nan_to_num(yerr, copy=False)
plt.errorbar(x, y1, yerr=yerr1, fmt="o-", capsize=3.0, ecolor="k")
plt.errorbar(x, y2, yerr=yerr2, fmt="o-", capsize=3.0, ecolor="k")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment