import numpy as np
import matplotlib.pyplot as plt
# 生成散点图数据
x_scatter = np.random.rand(50)
y_scatter = np.random.rand(50)
# 生成柱状图数据
x_bar = np.arange(5)
y_bar = np.random.randint(1, 10, size=5)
# 创建一个包含两个子图的图形
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6), gridspec_kw={'hspace': 0, 'wspace': 0.3})
# 绘制散点图
scatter = ax1.scatter(x_scatter, y_scatter, color='darkred', edgecolors='black')
ax1.set_xlabel('Categories')
ax1.set_ylabel('Values')
ax1.annotate('(a)', xy=(-0.1, 1.1), xycoords='axes fraction', fontsize=12)
# 绘制柱状图
bars = ax2.bar(x_bar, y_bar, edgecolor='black')
ax2.set_xlabel('Categories')
ax2.set_ylabel('Values')
ax2.annotate('(b)', xy=(-0.1, 1.1), xycoords='axes fraction', fontsize=12)
# 去掉标题
ax1.set_title('')
ax2.set_title('')
plt.show()
代码说明: