import matplotlib.pyplot as plt
import numpy as np
# Data for the plot
category_labels = ['Category 1', 'Category 2', 'Category 3', 'Category 4']
mean_values = [0.5, 0.8, 0.3, 0.6]
ci_low = [0.4, 0.7, 0.2, 0.5]
ci_high = [0.6, 0.9, 0.4, 0.7]
# Number of categories
n_categories = len(category_labels)
# Create a figure and axis
fig, ax = plt.subplots()
# Plot the horizontal lines
ax.hlines(np.arange(n_categories), ci_low, ci_high, colors='blue', zorder=10)
# Plot the markers for mean values
ax.plot(mean_values, np.arange(n_categories), 'o', color='red', markersize=5, zorder=20)
# Set the y-ticks and labels
ax.set_yticks(np.arange(n_categories))
ax.set_yticklabels(category_labels)
# Set the x-label
ax.set_xlabel('Mean Value')
# Invert the y-axis
ax.invert_yaxis()
# Add a grid
ax.grid(axis='x', linestyle='--', alpha=0.5)
# Show the plot
plt.show()
This code will create a forest plot with four categories. You can customize the data, labels, and formatting according to your needs.