使用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及字体颜色为白色。
时间: 2023-11-28 11:50:39 浏览: 31
1、定义x变量为随机生从20到100之间的100个数据,y变量为5x2-1。
```
import numpy as np
x = np.random.randint(20, 101, size=100)
y = 5 * x ** 2 - 1
```
2、使用Matplotlib库绘制x和y的散点图,颜色为黄色,标题为"y=5x^2-1"。
```
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"。
```
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"。
```
import seaborn as sns
sns.scatterplot(x=x, y=y, color='yellow')
plt.title('y=5x^2-1')
plt.show()
```
5、随机生成五组1-100之间的20个数据,计算他们的相关系数矩阵(pandas的dataframe有corr()方法可以计算相关系数矩阵),并绘制热力图,显示数字和保留2位小数,数字大小为8及字体颜色为白色。
```
data = np.random.randint(1, 101, size=(20, 5))
df = pd.DataFrame(data)
corr_matrix = df.corr()
plt.figure(figsize=(8, 8))
sns.heatmap(corr_matrix, annot=True, fmt='.2f', cmap='coolwarm', annot_kws={"size": 8, "color": "white"})
plt.show()
```
相关推荐
![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)
![](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)