欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python数据分析-Seaborn相关操作复习1

程序员文章站 2024-03-07 21:37:27
...

目录

1.Createing basic plots

1.Createing basic plots

# importing required libraries
import seaborn as sns
sns.set()
sns.set(style = "darkgrid")

import numpy as np
import pandas as pd

# importing matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

import warnings
warnings.filterwarnings("ignore")
plt.rcParams['figure.figsize']=(10,10)
# read the dataset
data_BM = pd.read_csv('bigmart_data.csv')
# drop the null values
data_BM = data_BM.dropna(how="any")
# multiply Item_Visibility by 100 to increase size
data_BM["Visibility_Scaled"] = data_BM["Item_Visibility"] * 100
# view the top results
#data_BM.head()

1.1 line chart

#line plot using replot
sns.lineplot(x = "Item_Weight",y ="Item_MRP",data = data_BM[:50]);

python数据分析-Seaborn相关操作复习1

1.2 bar chart

sns.barplot(x = "Item_Type",y = "Item_MRP",data = data_BM[:5])

python数据分析-Seaborn相关操作复习1

1.3 histogram chart

sns.distplot(data_BM['Item_MRP'])

python数据分析-Seaborn相关操作复习1

1.4 box plot

sns.boxplot(data_BM['Item_Outlet_Sales'],orient = 'vertical')

python数据分析-Seaborn相关操作复习1

1.5 violin plot

sns.violinplot((data_BM['Item_Outlet_Sales'], orient='vertical', color='magenta')

python数据分析-Seaborn相关操作复习1

1.6 scatter plot

sns.relplot(x="Item_MRP", y="Item_Outlet_Sales", data=data_BM[:200],kind = "scatter")

python数据分析-Seaborn相关操作复习1

1.7 Hue semantic

Hue semantic
We can also add another dimension to the plot by coloring the points according to a third variable. In seaborn, this is referred to as using a “hue semantic”.

sns.relplot(x="Item_MRP", y="Item_Outlet_Sales", hue="Item_Type",data=data_BM[:200]);

python数据分析-Seaborn相关操作复习1

# different line plots for different categories of the Outlet_Size
sns.lineplot(x="Item_Weight", y="Item_MRP",hue='Outlet_Size',data=data_BM[:150]);

python数据分析-Seaborn相关操作复习1

1.8 bubble plot

sns.replot(x="Item_MRP", y="Item_Outlet_Sales", data=data_BM[:200],kind = "scatter",size = "Visibility_Scaled",hue ="Visibility_Scaled" )

python数据分析-Seaborn相关操作复习1

# subplots for each of the category of Outlet_Size
sns.relplot(x="Item_Weight", y="Item_Visibility",hue='Outlet_Size',style='Outlet_Size',col='Outlet_Size',data=data_BM[:100]);

python数据分析-Seaborn相关操作复习1