import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
# Creating a custom layout with different subplot sizes
fig = plt.figure(figsize=(12, 6))
# Using gridspec to define the layout
gs = gridspec.GridSpec(2, 3, width_ratios=[1, 2, 1], height_ratios=[2, 1])
# Creating subplots based on the layout
ax1 = plt.subplot(gs[0, 0])
ax2 = plt.subplot(gs[0, 1])
ax3 = plt.subplot(gs[0, 2])
ax4 = plt.subplot(gs[1, :])
# Customizing each subplot with different visualizations
# Subplot 1: Line Plot
x = np.linspace(0, 10, 100)
y1 = np.sin(x)
ax1.plot(x, y1, color='blue')
ax1.set_title('Line Plot - Sine Function')
# Subplot 2: Scatter Plot
x = np.random.rand(30)
y2 = 3 * x + np.random.randn(30)
ax2.scatter(x, y2, color='green')
ax2.set_title('Scatter Plot')
# Subplot 3: Bar Plot
categories = ['A', 'B', 'C', 'D']
values = np.random.randint(1, 10, 4)
ax3.bar(categories, values, color='orange')
ax3.set_title('Bar Plot')
# Subplot 4: Pie Chart
labels = ['Category 1', 'Category 2', 'Category 3']
sizes = np.random.randint(1, 10, 3)
ax4.pie(sizes, labels=labels, autopct='%1.1f%%', colors=['lightcoral', 'lightblue', 'lightgreen'])
ax4.set_title('Pie Chart')
# Adjusting layout for better spacing
plt.tight_layout()
# Displaying the figure
plt.show()