seaborn.displot将纵轴显示为概率
时间: 2023-06-05 12:08:34 浏览: 153
分布时应该怎么做?
为了将纵轴显示为概率分布,您可以将参数设置为norm_hist=True。这将替换计数标准化,以便纵轴表示概率密度函数。例如:seaborn.displot(data, x='variable', kde=True, rug=True, norm_hist=True)。希望对您有所帮助!
相关问题
x = np.random.randn(100) ax = sns.displot(x) x = np.random.randn(100) ax = sns.displot(x) x = np.random.randn(100) ax = sns.displot(x) x = np.random.randn(100) ax = sns.displot(x) x = np.random.randn(100)ax = sns.displot(x) 写到pycharm里,pycharm为什么不出现图
在PyCharm中,你需要使用`plt.show()`来显示图形。添加这一行代码后,你的图形应该能够在PyCharm中正确显示。请尝试将以下代码添加到你的脚本中:
```python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme()
np.random.seed(0)
x = np.random.randn(100)
ax = sns.displot(x)
plt.show()
x = np.random.randn(100)
ax = sns.displot(x)
plt.show()
x = np.random.randn(100)
ax = sns.displot(x)
plt.show()
x = np.random.randn(100)
ax = sns.displot(x)
plt.show()
x = np.random.randn(100)
ax = sns.displot(x)
plt.show()
```
这样你就可以在PyCharm中看到生成的图形了。如果还有其他问题,请随时提问!
调用sns.displot()显示'DataFrame' object has no attribute 'to_frame'
sns.displot()是Seaborn库中的一个函数,用于绘制数据的分布图。根据你提供的错误信息,"'DataFrame' object has no attribute 'to_frame'",个错误提示表明你传递给sns.displot()函数的参数是一个DataFrame对象,但DataFrame对象没有to_frame()方法。
通常情况下,sns.displot()函数需要传递一个Series对象或者一个数组作为参数,而不是DataFrame对象。如果你想要绘制DataFrame对象中某一列的分布图,可以使用以下方法:
1. 提取DataFrame中的某一列作为Series对象,然后将该Series对象作为参数传递给sns.displot()函数。
示例代码如下:
```
import seaborn as sns
import pandas as pd
# 假设df是你的DataFrame对象,column_name是你想要绘制分布图的列名
series_data = df[column_name]
sns.displot(series_data)
```
2. 将DataFrame对象转换为数组,然后将该数组作为参数传递给sns.displot()函数。
示例代码如下:
```
import seaborn as sns
import pandas as pd
# 假设df是你的DataFrame对象,column_name是你想要绘制分布图的列名
array_data = df[column_name].values
sns.displot(array_data)
```
希望以上解释和示例代码能够帮助到你!如果还有其他问题,请随时提问。