4. distplot(a=,kde=False),直方图
kernel density estimate (KDE) kde不写,或者为True,会出现曲线
代码语言:javascript复制# 直方图 Histogram
filepath = "iris.csv"
iris_data = pd.read_csv(filepath, index_col='Id')
print(iris_data.head())
sns.distplot(a=iris_data['Petal Length (cm)'],kde=False)
plt.show()
分成几次分别绘制,带颜色
代码语言:javascript复制iris_set_file = "iris_setosa.csv"
iris_ver_file = "iris_versicolor.csv"
iris_vir_file = "iris_virginica.csv"
iris_set_data = pd.read_csv(iris_set_file, index_col="Id")
iris_ver_data = pd.read_csv(iris_ver_file, index_col="Id")
iris_vir_data = pd.read_csv(iris_vir_file, index_col="Id")
sns.distplot(a=iris_set_data["Petal Length (cm)"], label="iris_setosa", kde=False)
sns.distplot(a=iris_ver_data['Petal Length (cm)'], label="Iris-versicolor", kde=False)
sns.distplot(a=iris_vir_data['Petal Length (cm)'], label="Iris-virginica", kde=False)
plt.title("不同种系Petal Lengths直方图")
plt.legend()
plt.show()
5. kdeplot,密度图
5.1 kdeplot,一维密度图
代码语言:javascript复制# 密度图
sns.kdeplot(data=iris_data['Petal Length (cm)'], shade=False)
分开绘制密度图
代码语言:javascript复制sns.kdeplot(data=iris_set_data['Petal Length (cm)'], label="Iris-setosa", shade=True)
sns.kdeplot(data=iris_ver_data['Petal Length (cm)'], label="Iris-versicolor", shade=True)
sns.kdeplot(data=iris_vir_data['Petal Length (cm)'], label="Iris-virginica", shade=True)
plt.title("不同种系Petal Lengths分布")
plt.show()
5.2 jointplot(x=,y=,kind=‘kde’),二维密度图
代码语言:javascript复制sns.jointplot(x=iris_data['Petal Length (cm)'], y=iris_data['Sepal Width (cm)'],
kind='kde')
6. set_style(),设置底色
代码语言:javascript复制sns.set_style("dark") # 灰色底色
# (1)"darkgrid", (2)"whitegrid", (3)"dark", (4)"white", and (5)"ticks"
代码语言:javascript复制style = ["dark", "darkgrid", "white", "whitegrid", "ticks"]
plt.figure(figsize=(12, 6))
for i in range(5):
sns.set_style(style[i])
f = plt.subplot(2, 3, i 1)
sns.lineplot(data=data) # 单个数据可以加 label="label_test"
f.set_title("style_" style[i])
f.legend()
plt.show()