How to make graph like this in Python
I saw a nice graph from posting in https://x.com/junwatu/status/1851779704510124178/photo/1
Let’s ask Claude to imitate the graph.
I’ll help you create a similar line graph using Python, primarily using matplotlib with a modern, dark theme that matches the style of the image.
This code creates a graph similar to the one shown in your image. Here are the key features:
- Uses a dark theme matching GitHub’s dark mode
- Creates smooth lines with dots at data points
- Places country labels at the end of each line
- Uses custom colors for each country
- Includes a grid for better readability
- Removes chart borders for a modern look
- Reverses the y-axis to show rank 1 at the top
import matplotlib.pyplot as plt
import numpy as np
# Sample data
countries = ['India', 'United States', 'China', 'Brazil', 'United Kingdom',
'Indonesia', 'Japan', 'Germany', 'Russia', 'Canada']
# Create sample data for demonstration
# In reality, you would have your actual data here
years = np.array([2024, 2025, 2026, 2027, 2028])
data = np.array([
[1, 1, 1, 2, 2], # India
[2, 2, 2, 1, 1], # United States
[3, 3, 3, 3, 3], # China
[4, 4, 4, 4, 4], # Brazil
[5, 5, 5, 5, 5], # UK
[8, 6, 6, 6, 6], # Indonesia
[7, 7, 7, 7, 7], # Japan
[9, 8, 8, 8, 8], # Germany
[6, 9, 9, 9, 9], # Russia
[10, 10, 10, 10, 10] # Canada
])
# Set the style
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(12, 8))
# Custom colors for each line
colors = ['#FF69B4', '#9370DB', '#87CEEB', '#90EE90', '#FFD700',
'#FF6347', '#DDA0DD', '#BA55D3', '#ADD8E6', '#98FB98']
# Plot each line
for i, (country, color) in enumerate(zip(countries, colors)):
ax.plot(years, data[i], color=color, linewidth=2, marker='o', markersize=8)
# Add country name at the end of each line
ax.text(years[-1] + 0.1, data[i, -1], country, color=color,
verticalalignment='center', fontsize=10)
# Customize the plot
ax.set_ylim(10.5, 0.5) # Reverse y-axis and add some padding
ax.set_xlim(2024, 2028.5) # Add space for labels on the right
# Set title
plt.title('Projecting the top 10 developers communities\non GitHub 2024-2028',
fontsize=16, pad=20)
# Customize grid
ax.grid(True, linestyle='--', alpha=0.2)
# Customize axes
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
# Set y-axis ticks
ax.set_yticks(range(1, 11))
# Remove x-axis ticks but keep labels
ax.tick_params(axis='x', length=0)
# Set background color
fig.patch.set_facecolor('#0D1117')
ax.set_facecolor('#0D1117')
# Adjust layout
plt.tight_layout()
# Show plot
plt.show()
To use this code, you’ll need to have matplotlib installed. You can install it using:
pip install matplotlib
You can modify the data array to match your actual data points. Each row represents a country’s ranking over the years.