相对于冬季来说,夏季通常温度、湿度较高,空气质量较好,请用numpy.random.randint()函数分别生成两个季节的20组数据,并以温度、湿度、空气质量为三个坐标,绘制3D散点图。
已有程序如下,缺失【1】-【5】
import numpy as np
import matplotlib. 【1】 as plt
相对于冬季来说,夏季通常温度、湿度较高,空气质量较好,请用numpy.random.randint()函数分别生成两个季节的20组数据,并以温度、湿度、空气质量为三个坐标,绘制3D散点图。
已有程序如下,缺失【1】-【5】
import numpy as np
import matplotlib. 【1】 as plt
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
plt.rcParams['font.sans-serif'] = ['SimHei'] # 避免中文出现乱码
plt.rcParams['axes.unicode_minus'] = False
N = 20
fig = plt.figure(figsize=(6, 5))
ax = Axes3D(fig, elev=45, azim=45)
# 添加散点图
ax.scatter(
np.random.randint(25, 38, N),
np.random.randint(50, 90, N),
nprandom.randint(10, 30, N),
marker='x',
label='夏季',
c='r',
edgecolors='r'
)
ax.scatter(
np.random.randint(1, 10, N),
np.random.randint(10, 40, N),
np.random.randint(50, 90, N),
marker='>',
label='冬季',
c='g',
edgecolors='g'
)
# 设置坐标轴标签
ax.set_xlabel('温度C')
ax.set_ylabel('湿度%')
ax.set_zlabel('空气质量')
# 设置视角距离和图例
ax.dist = 11
plt.legend()
# 显示图形
plt.show()
以上是完整的Python代码: