Area Chart
ROC Curve with AUC
Receiver operating characteristic with confidence region - R style
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# Simulate ROC curve
fpr = np.linspace(0, 1, 100)
tpr_model = 1 - (1 - fpr)**2.5 # Good model
tpr_random = fpr # Random
# CI simulation
tpr_low = np.clip(tpr_model - 0.08 - 0.05*fpr, 0, 1)
tpr_high = np.clip(tpr_model + 0.05 + 0.03*fpr, 0, 1)
# Manual AUC calculation (trapezoidal rule)
auc = np.sum((fpr[1:] - fpr[:-1]) * (tpr_model[1:] + tpr_model[:-1]) / 2)
fig, ax = plt.subplots(figsize=(10, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
ax.fill_between(fpr, tpr_low, tpr_high, alpha=0.25, color='#4927F5')
ax.fill_between(fpr, 0, tpr_model, alpha=0.15, color='#4927F5')
ax.plot(fpr, tpr_model, color='#4927F5', linewidth=2.5, label=f'Model (AUC = {auc:.3f})')
ax.plot(fpr, tpr_random, color='#9ca3af', linewidth=1.5, linestyle='--', label='Random (AUC = 0.500)')
# Optimal threshold point (Youden's J)
opt_idx = np.argmax(tpr_model - fpr)
ax.scatter([fpr[opt_idx]], [tpr_model[opt_idx]], color='#F5276C', s=120, zorder=5, edgecolors='white', linewidth=2)
ax.annotate(f'Optimal\n({fpr[opt_idx]:.2f}, {tpr_model[opt_idx]:.2f})',
(fpr[opt_idx], tpr_model[opt_idx]), xytext=(25, -25), textcoords='offset points',
color='#F5276C', fontsize=10, fontweight='bold',
arrowprops=dict(arrowstyle='->', color='#F5276C', lw=1.5))
ax.set_xlabel('False Positive Rate (1 - Specificity)', color='#1f2937', fontsize=11, fontweight='500')
ax.set_ylabel('True Positive Rate (Sensitivity)', color='#1f2937', fontsize=11, fontweight='500')
ax.set_title('ROC Curve with 95% Confidence Band', color='#1f2937', fontsize=13, fontweight='600', pad=15)
ax.tick_params(colors='#374151', labelsize=9)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#e5e7eb')
ax.spines['bottom'].set_color('#e5e7eb')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1.02)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', labelcolor='#1f2937', loc='lower right', fontsize=10)
ax.yaxis.grid(True, color='#f3f4f6', linewidth=0.8)
ax.xaxis.grid(True, color='#f3f4f6', linewidth=0.8)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Area Chart examples
☕