使用Python,完成以下任务: 1、定义x变量为随机生从20到100之间的100个数据,y变量为5x2-1。 2、使用Matplotlib库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。 3、使用Pandas库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。 4、使用Seaborn库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。 5、随机生成五组1-100之间的20个数据,计算他们的相关系数矩阵(
时间: 2023-11-28 13:50:58 浏览: 34
1. 定义x变量为随机生成从20到100之间的100个数据,y变量为5x^2-1。
```python
import random
x = [random.randint(20, 100) for i in range(100)]
y = [(5 * i ** 2) - 1 for i in x]
```
2. 使用Matplotlib库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。
```python
import matplotlib.pyplot as plt
plt.scatter(x, y, color='yellow')
plt.title("y=5x^2-1")
plt.show()
```
3. 使用Pandas库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。
```python
import pandas as pd
df = pd.DataFrame({'x': x, 'y': y})
df.plot.scatter(x='x', y='y', color='yellow', title="y=5x^2-1")
plt.show()
```
4. 使用Seaborn库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。
```python
import seaborn as sns
sns.scatterplot(x=x, y=y, color='yellow')
plt.title("y=5x^2-1")
plt.show()
```
5. 随机生成五组1-100之间的20个数据,计算它们的相关系数矩阵。
```python
import numpy as np
# 生成数据
data = []
for i in range(5):
data.append([random.randint(1, 100) for j in range(20)])
# 计算相关系数矩阵
corr_matrix = np.corrcoef(data)
print(corr_matrix)
```
相关推荐
![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_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)