目录
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]);
1.2 bar chart
sns.barplot(x = "Item_Type",y = "Item_MRP",data = data_BM[:5])
1.3 histogram chart
sns.distplot(data_BM['Item_MRP'])
1.4 box plot
sns.boxplot(data_BM['Item_Outlet_Sales'],orient = 'vertical')
1.5 violin plot
sns.violinplot((data_BM['Item_Outlet_Sales'], orient='vertical', color='magenta')
1.6 scatter plot
sns.relplot(x="Item_MRP", y="Item_Outlet_Sales", data=data_BM[:200],kind = "scatter")
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]);
# 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]);
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" )
# 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]);