Raincloud Plot

Crop Yield by Fertilizer Type

Agricultural output across treatments

Output
Crop Yield by Fertilizer Type
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(214)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#6CF527', '#F5B027', '#27D3F5', '#F5276C']

ferts = ['Organic', 'Synthetic', 'Hybrid', 'Control']
data = pd.DataFrame({
    'Yield': np.concatenate([
        np.random.normal(45, 8, 80),
        np.random.normal(55, 10, 85),
        np.random.normal(52, 9, 90),
        np.random.normal(38, 7, 75)
    ]),
    'Fertilizer': ['Organic']*80 + ['Synthetic']*85 + ['Hybrid']*90 + ['Control']*75
})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

pt.RainCloud(x='Fertilizer', y='Yield', data=data, palette=COLORS,
             bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
             dodge=True, pointplot=False, move=.2)

ax.set_xlabel('Yield (tons/hectare)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Fertilizer Type', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Crop Yield by Fertilizer', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support