scatter 画四组数据
时间: 2023-09-10 18:06:39 浏览: 28
好的,以下是使用matplotlib库的scatter函数画出四组数据的例子:
```python
import matplotlib.pyplot as plt
import numpy as np
# 生成数据
x1 = np.random.rand(50)
y1 = np.random.rand(50)
x2 = np.random.rand(50)
y2 = np.random.rand(50)
x3 = np.random.rand(50)
y3 = np.random.rand(50)
x4 = np.random.rand(50)
y4 = np.random.rand(50)
# 绘制散点图
plt.scatter(x1, y1, color='red')
plt.scatter(x2, y2, color='blue')
plt.scatter(x3, y3, color='green')
plt.scatter(x4, y4, color='orange')
# 添加标题和标签
plt.title('Four Groups of Data')
plt.xlabel('X')
plt.ylabel('Y')
# 显示图形
plt.show()
```
这段代码会生成一个包含四组随机数据散点图的图形。你可以根据自己的需要修改数据和颜色等参数。
相关问题
matlab scatter 画四组数据
假设你有四组数据,分别为x1, y1, x2, y2, x3, y3, x4, y4,可以使用Matlab的scatter函数进行绘制。以下是一个简单的例子:
```
% 生成数据
x1 = rand(1, 50);
y1 = rand(1, 50);
x2 = rand(1, 50);
y2 = rand(1, 50);
x3 = rand(1, 50);
y3 = rand(1, 50);
x4 = rand(1, 50);
y4 = rand(1, 50);
% 绘制散点图
figure;
hold on;
scatter(x1, y1, 'filled');
scatter(x2, y2, 'filled');
scatter(x3, y3, 'filled');
scatter(x4, y4, 'filled');
legend('Group 1', 'Group 2', 'Group 3', 'Group 4');
```
这个例子中,我们先生成了四组随机数据,并使用scatter函数绘制了四张散点图。通过'filled'参数,我们将散点图中的点填充为实心的点。最后使用legend函数添加图例,便于区分每组数据。
matlab画多组数据散点图
可以使用MATLAB中的xlsread函数读取Excel文件中的数据,然后使用scatter函数画出散点图。具体步骤如下:
1. 使用xlsread函数读取Excel文件中的数据,例如:
```matlab
data = xlsread('data.xlsx');
```
其中,'data.xlsx'是Excel文件的文件名,data是读取到的数据。
2. 使用scatter函数画出散点图,例如:
```matlab
scatter(data(:,1), data(:,2));
```
其中,data(:,1)和data(:,2)分别表示数据中的第一列和第二列,即横坐标和纵坐标。
完整代码示例:
```matlab
data = xlsread('data.xlsx');
scatter(data(:,1), data(:,2));
```
注意:在使用xlsread函数读取Excel文件时,需要保证Excel文件中的数据格式正确,且文件路径正确。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)