写一个Python生成散点图的代码
时间: 2023-09-07 22:05:19
浏览: 77
### 回答1:
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [2,4,6,8,10]
plt.scatter(x,y)
plt.xlabel('x 轴')
plt.ylabel('y 轴')
plt.show()
### 回答2:
下面是一种使用Python生成散点图的[代码]([http]([http](https://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083):
```python
import matplotlib.pyplot as plt
# [定义](https://geek.csdn.net/educolumn/76417ec98a39b9ca5cc3d7e6f65ac4a1?spm=1055.2569.3001.10083)数据
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# 绘制散点图
plt.scatter(x, y)
# 设置图表标题和坐标轴标签
plt.title('Scatter Plot')
plt.xlabel('X')
plt.ylabel('Y')
# [显示](https://geek.csdn.net/educolumn/103ca72607c717122e068b9f06a24df6?spm=1055.2569.3001.10083)图表
plt.show()
```