Raincloud Plot
CO2 Emissions by Vehicle Type
Carbon footprint distribution across transport modes
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(119)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#6CF527', '#F5B027', '#F54927', '#9C2007']
types = ['EV', 'Hybrid', 'Gas', 'Diesel']
data = pd.DataFrame({
'CO2': np.concatenate([
np.random.gamma(2, 5, 80),
np.random.gamma(4, 12, 90),
np.random.gamma(6, 20, 100),
np.random.gamma(7, 22, 85)
]),
'Type': ['EV']*80 + ['Hybrid']*90 + ['Gas']*100 + ['Diesel']*85
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Type', y='CO2', data=data, palette=COLORS,
bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
dodge=True, pointplot=False, move=.2)
ax.set_xlabel('CO2 Emissions (g/km)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Vehicle Type', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Carbon Emissions by Vehicle Type', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Raincloud Plot examples
☕