Menu

Tutorial8 min read

ROC Curves in Python: How to Plot AUC, Thresholds, and Confidence Intervals

By Francesco VillasmuntaUpdated March 21, 2026
ROC Curves in Python: How to Plot AUC, Thresholds, and Confidence Intervals

ROC curves are useful when you need to show how well a classifier separates two classes across all thresholds. In clinical research, they are often paired with AUC, sensitivity, specificity, and an operating threshold chosen for a practical cutoff rather than a mathematically perfect one.

AUC

Summarizes ranking performance across thresholds.

Threshold

Shows where sensitivity and specificity balance for your use case.

Confidence

Useful when reviewers expect uncertainty around model performance.

Compact ROC code

For most publication figures, start with `roc_curve` and `roc_auc_score`, then annotate the threshold you plan to use in the real workflow.

Try it

Try it now: generate your ROC curve

Build an ROC figure with AUC annotation and threshold-aware styling from your own classification results.

Generate my ROC curve

Newsletter

Get a weekly Python plotting tip

One concise tip each week for cleaner, faster scientific figures. Built for researchers who publish.

No spam. Unsubscribe anytime.
from sklearn.metrics import roc_curve, roc_auc_score
import matplotlib.pyplot as plt
import numpy as np

y_true = np.array([0, 0, 1, 1, 0, 1, 0, 1])
y_score = np.array([0.10, 0.35, 0.72, 0.81, 0.22, 0.90, 0.40, 0.76])

fpr, tpr, thresholds = roc_curve(y_true, y_score)
auc = roc_auc_score(y_true, y_score)

fig, ax = plt.subplots(figsize=(6, 6))
ax.plot(fpr, tpr, lw=2, label=f"Model (AUC = {auc:.2f})")
ax.plot([0, 1], [0, 1], "--", color="gray", label="Chance")
ax.set_xlabel("False Positive Rate")
ax.set_ylabel("True Positive Rate")
ax.set_title("ROC Curve")
ax.legend(frameon=False)
plt.tight_layout()

What to label

  • State the AUC in the legend or caption.
  • Mark the chosen operating point if the figure supports a clinical decision.
  • Explain whether the curve is from cross-validation, holdout data, or a test set.
  • If you show a confidence band, say how it was computed.

Good fit

Diagnostic tests, binary classifiers, biomarker studies, and any scenario where a threshold decision matters.

Poor fit

Problems with heavily imbalanced classes, multi-class workflows, or cases where precision-recall curves communicate the story more honestly.

If you need a broader clinical workflow, read the clinical research figures guide, then compare it with the ROC technique page.

Try Plotivy with classifier results
Tags:#ROC curve#AUC#python#clinical research#classification

Found this helpful? Share it with your network.

FV
Francesco Villasmunta

Experimental Physicist & Photonics Researcher

Hands-on experience in silicon photonics, semiconductor fabrication (DRIE/ICP-RIE), optical simulation, and data-driven analysis. Built Plotivy to help researchers focus on discoveries instead of data struggles.

More about the author

Visualize your own data

Apply the techniques from this article to your own datasets. Upload CSV, Excel, or paste data directly.

Start Analyzing - Free