Stackplot

Sentiment Stream

Social sentiment by emotion type.

Output
Sentiment Stream
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'joy': '#10B981',
    'surprise': '#F59E0B',
    'neutral': '#94A3B8',
    'sadness': '#3B82F6',
    'anger': '#EF4444',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9'
}

np.random.seed(42)
hours = np.arange(48)
joy = 30 + 10*np.sin(hours/6) + np.random.normal(0, 3, 48)
surprise = 15 + 8*np.sin(hours/8 + 1) + np.random.normal(0, 2, 48)
neutral = 25 + 5*np.sin(hours/10) + np.random.normal(0, 2, 48)
sadness = 15 + 6*np.sin(hours/7 + 2) + np.random.normal(0, 2, 48)
anger = 10 + 4*np.sin(hours/5 + 3) + np.random.normal(0, 1.5, 48)

fig, ax = plt.subplots(figsize=(12, 5), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

ax.stackplot(hours, joy, surprise, neutral, sadness, anger,
             colors=[COLORS['joy'], COLORS['surprise'], COLORS['neutral'], COLORS['sadness'], COLORS['anger']],
             alpha=0.85, baseline='wiggle', labels=['Joy', 'Surprise', 'Neutral', 'Sadness', 'Anger'])

ax.axhline(0, color=COLORS['text'], linewidth=0.5)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_visible(False)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xlim(0, 47)
ax.set_xlabel('Hours', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), ncol=5, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support