Event Plot
Trade Execution Timeline
Buy and sell order executions across trading assets
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Simulate trade executions
np.random.seed(42)
assets = ['AAPL', 'GOOGL', 'MSFT', 'AMZN', 'TSLA']
trade_times = [
np.sort(np.random.exponential(0.3, 80).cumsum()),
np.sort(np.random.exponential(0.5, 50).cumsum()),
np.sort(np.random.exponential(0.25, 100).cumsum()),
np.sort(np.random.exponential(0.4, 65).cumsum()),
np.sort(np.random.exponential(0.2, 120).cumsum()),
]
# Buy/Sell simulation
trade_types = [np.random.choice([1, -1], len(t)) for t in trade_times]
# Create figure
fig, ax = plt.subplots(figsize=(12, 6), facecolor='white')
for i, (times, types) in enumerate(zip(trade_times, trade_types)):
buys = times[types == 1]
sells = times[types == -1]
# Buy orders (green)
ax.eventplot(buys, lineoffsets=i + 0.15, linelengths=0.25, linewidths=1.5,
colors='#10B981', alpha=0.8)
# Sell orders (red)
ax.eventplot(sells, lineoffsets=i - 0.15, linelengths=0.25, linewidths=1.5,
colors='#EF4444', alpha=0.8)
# Market open/close
ax.axvline(0, color='#6B7280', linewidth=2, linestyle='-')
ax.axvline(23, color='#6B7280', linewidth=2, linestyle='-')
ax.text(0.3, 4.7, 'Market Open', fontsize=9, color='#6B7280')
ax.text(21.5, 4.7, 'Close', fontsize=9, color='#6B7280')
# Legend
ax.eventplot([], lineoffsets=0, colors='#10B981', label='Buy')
ax.eventplot([], lineoffsets=0, colors='#EF4444', label='Sell')
ax.legend(loc='upper right', frameon=True, facecolor='white', fontsize=10)
# Styling
ax.set_yticks(range(len(assets)))
ax.set_yticklabels(assets, fontsize=12, fontweight='700', family='monospace')
ax.set_xlabel('Trading Hours', fontsize=12, fontweight='500', color='#374151')
ax.set_xlim(-0.5, 24)
ax.set_ylim(-0.5, len(assets) - 0.5)
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.tick_params(colors='#6B7280', labelsize=10)
ax.xaxis.grid(True, linestyle='--', alpha=0.3, color='#D1D5DB')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Event Plot examples
☕