Matplotlib Volcano Plot

This example demonstrates how to create a volcano plot using the Matplotlib library.

import numpy as np
import matplotlib.pyplot as plt

# Generate random data
x = np.random.normal(0, 1, 100)
y = np.random.normal(0, 1, 100)

# Calculate log fold change and p-values
log_fold_change = np.log2(x / y)
p_values = -np.log10(np.random.uniform(0, 1, 100))

# Create volcano plot
plt.scatter(log_fold_change, p_values, color='black', alpha=0.5)
plt.axhline(y=-np.log10(0.05), color='red', linestyle='--')
plt.axvline(x=0, color='gray', linestyle='--')
plt.xlabel('Log Fold Change')
plt.title('Volcano Plot')