08 · Explorative Datenanalyse und Datenvisualisierung
streu_crp_verweildauer.png
Abbildung · Quellcode

Erzeugt in plot_crp_los_scatter() – hier steht nur der Teil, der zeichnet in module/08-eda-visualisierung/code/python.py, Zeile 144–166.
Python
Python-Code: in eine Datei mit Endung
.py schreiben und mit dem ▶-Knopf in VS Code ausführen – oder Zeile für Zeile in die Python-Konsole. Setzt die in Modul 02 eingerichtete Umgebung voraus.fig, ax = plt.subplots(figsize=(7, 5)) colors = {0: PRIMARY, 1: EVENT} for outcome, label in [(0, "Überlebt"), (1, "Verstorben")]: subset = df[df["verstorben_30d"] == outcome] ax.scatter(subset["crp_mg_l"], subset["verweildauer_tage"], c=colors[outcome], label=label, alpha=0.42, s=22, edgecolors="none") ax.set_xlabel("CRP (mg/l)") ax.set_ylabel("Verweildauer (Tage)") ax.set_title("CRP vs. Verweildauer nach 30-Tage-Mortalität") # Overall linear trend line (same as data/figures.py). mask = df["crp_mg_l"].notna() & df["verweildauer_tage"].notna() x_all = df.loc[mask, "crp_mg_l"].to_numpy() y_all = df.loc[mask, "verweildauer_tage"].to_numpy() coef = np.polyfit(x_all, y_all, 1) x_range = np.linspace(x_all.min(), x_all.max(), 200) ax.plot(x_range, np.poly1d(coef)(x_range), color="#555555", linewidth=1.1, linestyle="--", alpha=0.7, label="Trend (gesamt)") ax.legend() fig.tight_layout() path = FIGURE_DIR / "streu_crp_verweildauer.png" fig.savefig(FIGURE_DIR / "streu_crp_verweildauer.png", dpi=120) # literal path: lets the site link this code