代码:# 生成并绘制随机双变量数据集 x = food['胆固醇(每日参考值百分比)'].values y = food['钠(每日参考值百分比)'].values sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=axes[0,0]) axes[0,0].set(xlim=(-10, 50), ylim=(-30, 70), title = '胆固醇和钠') cmap = sns.cubehelix_palette(start=0.333333333333, light=1, as_cmap=True)。报错:TypeError: kdeplot() takes from 0 to 1 positional arguments but 2 positional arguments (and 2 keyword-only arguments) were given
时间: 2024-01-06 17:06:29 浏览: 43
这个报错可能是因为缺少了 `data` 参数,你需要将 x 和 y 作为一个二维数组传递给 `data` 参数。可以尝试修改代码如下:
```
import numpy as np
import seaborn as sns
x = food['胆固醇(每日参考值百分比)'].values
y = food['钠(每日参考值百分比)'].values
cmap = sns.cubehelix_palette(start=0.333333333333, light=1, as_cmap=True)
sns.kdeplot(data=np.column_stack((x, y)), cmap=cmap, shade=True, cut=5)
plt.xlim(-10, 50)
plt.ylim(-30, 70)
plt.title('胆固醇和钠')
plt.show()
```
这样应该就可以生成并绘制随机双变量数据集了。
相关问题
# 绘制KDE图 f, axes = plt.subplots(3, 3, figsize=(10, 10), sharex=True, sharey=True) s = np.linspace(0, 3, 10) cmap = sns.cubehelix_palette(start=0.0, light=1, as_cmap=True) # 生成并绘制随机双变量数据集 x = food['胆固醇(每日参考值百分比)'].values y = food['钠(每日参考值百分比)'].values sns.kdeplot(x, y, cmap=cmap, shade=True, cut=5, ax=axes[0,0]) axes[0,0].set(xlim=(-10, 50), ylim=(-30, 70), title = '胆固醇和钠'),报错信息:OptionError: "No such keys(s): 'mode.use_inf_as_null'"
这个错误通常是因为您使用的Seaborn版本过低导致的。请升级您的Seaborn版本,方法如下:
```
!pip install seaborn --upgrade
```
或者,您可以尝试在导入Seaborn时显式地设置`mode.use_inf_as_null`参数,如下所示:
```
import seaborn as sns
sns.set(style="white", color_codes=True, rc={"mode.use_inf_as_null": True})
```
这样应该可以解决您的问题。
请生成数据集(X,y),其中X为分布于0到3之间的随机变量,并令y=2+4*X+np.random.randn(100,1);利用matplotlib画出生成的数据集
好的,以下是生成数据集(X,y)的代码和绘制散点图的代码:
```python
import numpy as np
import matplotlib.pyplot as plt
# 生成随机变量X
X = 3 * np.random.rand(100, 1)
# 生成对应的y
y = 2 + 4 * X + np.random.randn(100, 1)
# 绘制散点图
plt.scatter(X, y)
plt.xlabel("X")
plt.ylabel("y")
plt.show()
```
运行以上代码会生成一张散点图,其中横坐标为X,纵坐标为y,如下图所示:
![scatter_plot.png](https://img-blog.csdn.net/2018073016165032?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3ZpZGVvX2Jsb2c=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
相关推荐
![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)