数据可视化
1. 使用 matplotlib 库
import matplotlib.pyplot as plt
# 创建数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 使用 matplotlib 绘制散点图
plt.scatter(x, y, label='Data Points', color='blue', marker='o')
# 添加标签和标题
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot')
# 添加图例和网格
plt.legend()
plt.grid(True)
# 显示图形
plt.show()

matplotlib 库说明:
- 导入库:
import matplotlib.pyplot as plt - 创建数据:
x = [1, 2, 3, 4, 5]和y = [2, 3, 5, 7, 11] - 绘制散点图:
plt.scatter(x, y, label='Data Points', color='blue', marker='o') - 添加标签和标题:
plt.xlabel(),plt.ylabel(),plt.title() - 添加图例和网格:
plt.legend(),plt.grid(True) - 显示图形:
plt.show()
2. 使用 seaborn 库
import seaborn sns
matplotlib.pyplot plt
x = [, , , , ]
y = [, , , , ]
sns.scatterplot(x=x, y=y, label=)
plt.xlabel()
plt.ylabel()
plt.title()
plt.legend()
plt.grid()
plt.show()



