📜  Python – seaborn.factorplot() 方法

📅  最后修改于: 2022-05-13 01:55:02.707000             🧑  作者: Mango

Python – seaborn.factorplot() 方法

Seaborn是一个惊人的Python统计图形绘图可视化库。它提供了漂亮的默认样式和调色板,使统计图更具吸引力。它建立在 matplotlib 库之上,并且与 pandas 的数据结构紧密集成。

seaborn.factorplot() 方法

seaborn.factorplot()方法用于在 FacetGrid 上绘制分类图。

注意:要下载提示数据集,请单击此处。下面的示例说明了 seaborn 库的 factorplot() 方法。示例 1:

Python3
# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# point plot(by default)
sns.factorplot(x ='size', y ='tip', data = df)
 
# Show the plot
plt.show()


Python3
# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# point plot using hue attribute
# for colouring out points
# according to the sex
sns.factorplot(x ='size', y ='tip',
               hue = 'sex', data = df)
 
# Show the plot
plt.show()


输出 : 点图示例 2:

Python3

# importing the required library
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# read a csv file
df = pd.read_csv('Tips.csv')
 
# point plot using hue attribute
# for colouring out points
# according to the sex
sns.factorplot(x ='size', y ='tip',
               hue = 'sex', data = df)
 
# Show the plot
plt.show()

输出 : 彩色点图