Area Chart

Difference Fill

Surplus/deficit between actual and target.

Output
Difference Fill
Python
import matplotlib.pyplot as plt
import numpy as np

# Data - Actual vs Target
months = np.arange(1, 13)
target = [100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155]
actual = [95, 108, 102, 118, 128, 120, 138, 142, 135, 152, 148, 160]

# Figure - LIGHT THEME
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

# Difference areas
ax.fill_between(months, actual, target, where=(np.array(actual) >= np.array(target)), 
                alpha=0.5, color='#27F5B0', label='Above target', interpolate=True)
ax.fill_between(months, actual, target, where=(np.array(actual) < np.array(target)), 
                alpha=0.5, color='#F5276C', label='Below target', interpolate=True)
ax.plot(months, target, color='#374151', linewidth=2, linestyle='--', label='Target')
ax.plot(months, actual, color='#276CF5', linewidth=2.5, label='Actual')

# Styling
ax.set_xlabel('Month', color='#1f2937', fontsize=11)
ax.set_ylabel('Sales ($K)', color='#1f2937', fontsize=11)
ax.set_title('Sales Performance vs Target', color='#1f2937', fontsize=14, fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=9)
ax.set_xticks(months)
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], rotation=45)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.yaxis.grid(True, color='#f3f4f6', linewidth=0.5)
ax.legend(facecolor='#ffffff', edgecolor='#e5e7eb', labelcolor='#1f2937')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support