Skip to content

Instantly share code, notes, and snippets.

@khaosans
Created March 29, 2025 09:31
Show Gist options
  • Select an option

  • Save khaosans/59d44c263738daf3b440691147cd83b9 to your computer and use it in GitHub Desktop.

Select an option

Save khaosans/59d44c263738daf3b440691147cd83b9 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
# Data for Uniswap V1–V4 Comparison
versions = ['V1', 'V2', 'V3', 'V4']
capital_efficiency = [1.0, 1.2, 4.0, 5.0]
inverse_cost = [2.0, 2.5, 3.3, 5.0]
risk_tools = [1, 2, 3, 5]
il_inverted = [1.0, 1.5, 3.0, 4.0]
fees_earned = [1.0, 1.5, 3.5, 4.5]
# X-axis setup
x = np.arange(len(versions))
width = 0.15
# Color palette
colors = ['#3498DB', '#2ECC71', '#F39C12', '#E74C3C', '#9B59B6']
# Create the plot
fig, ax = plt.subplots(figsize=(12, 6))
bars1 = ax.bar(x - 2*width, capital_efficiency, width, label='Capital Efficiency', color=colors[0])
bars2 = ax.bar(x - width, inverse_cost, width, label='Inverse Cost', color=colors[1])
bars3 = ax.bar(x, risk_tools, width, label='Risk Tools Maturity', color=colors[2])
bars4 = ax.bar(x + width, il_inverted, width, label='Impermanent Loss (Inverted)', color=colors[3])
bars5 = ax.bar(x + 2*width, fees_earned, width, label='Fees Earned', color=colors[4])
# Labels and title
ax.set_title('📊 Uniswap V1–V4: Metric-by-Metric Comparison', fontsize=16, fontweight='bold')
ax.set_xlabel('Uniswap Versions', fontsize=12)
ax.set_ylabel('Relative Scores (Normalized)', fontsize=12)
ax.set_xticks(x)
ax.set_xticklabels(versions)
ax.legend(loc='upper left', bbox_to_anchor=(1, 1))
# Annotate bars
def annotate_bars(bars, color):
for bar in bars:
height = bar.get_height()
ax.annotate(f'{height:.1f}',
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 4),
textcoords="offset points",
ha='center', va='bottom',
fontsize=9, fontweight='bold', color=color)
annotate_bars(bars1, colors[0])
annotate_bars(bars2, colors[1])
annotate_bars(bars3, colors[2])
annotate_bars(bars4, colors[3])
annotate_bars(bars5, colors[4])
# Style
ax.grid(axis='y', linestyle='--', alpha=0.6)
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment