使用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个数据,计算他们的相关系数矩阵(pandas的dataframe有corr()方法可以计算相关系数矩阵),并绘制热力图,显示数字和保留2位小数,数字大小为8及字体颜色为白色。
时间: 2024-02-21 21:58:02 浏览: 15
以下是Python代码实现:
```python
import random
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 定义x变量为随机生从20到100之间的100个数据,y变量为5x2-1
x = np.array([random.randint(20, 100) for i in range(100)])
y = 5 * x ** 2 - 1
# 使用Matplotlib库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"
plt.scatter(x, y, c='yellow')
plt.title("y=5x^2-1")
# 使用Pandas库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"
df = pd.DataFrame({'x': x, 'y': y})
df.plot.scatter(x='x', y='y', c='yellow', title="y=5x^2-1")
# 使用Seaborn库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"
sns.scatterplot(x=x, y=y, color='yellow').set(title="y=5x^2-1")
# 随机生成五组1-100之间的20个数据,并计算相关系数矩阵
data = np.random.randint(1, 100, size=(20, 5))
df = pd.DataFrame(data)
corr_matrix = df.corr()
# 绘制热力图,显示数字和保留2位小数,数字大小为8及字体颜色为白色
sns.heatmap(corr_matrix, annot=True, fmt='.2f', cmap='coolwarm', annot_kws={"size": 8, "color": "white"})
plt.show()
```
注意需要提前安装好Matplotlib、Pandas、Seaborn等库。
相关推荐
![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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)