import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["font.sans-serif"] = ["SimHei"]
plt.rcParams["axes.unicode_minus"] = False
regions = ['东北', '中南', '华东', '华北', '西南']
years = [2015, 2016, 2017, 2018, 2019]
data = np.random.randint(50, 100, size=(5, 5))
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')
colors = ['r', 'g', 'b', 'y', 'c']
x_pos = np.arange(len(regions))
y_pos = np.arange(len(years))
x_pos, y_pos = np.meshgrid(x_pos, y_pos)
x_pos = x_pos.flatten()
y_pos = y_pos.flatten()
z_pos = np.zeros_like(x_pos)dx = dy = 0.8
dz = data.flatten()for i, (x, y, z, h) in enumerate(zip(x_pos, y_pos, z_pos, dz)):ax.bar3d(x, y, z, dx, dy, h, color=colors[i % len(colors)], alpha=0.8)
ax.set_xticks(np.arange(len(regions)))
ax.set_yticks(np.arange(len(years)))
ax.set_xticklabels(regions)
ax.set_yticklabels(years)
ax.set_zlabel('销售额')
ax.view_init(elev=20, azim=45)
plt.title('每年每地区的销售额')
plt.tight_layout()
plt.show()