用 SeaBorn 创建点图 – Python Pandas


seaborn.pointplot() 用于创建点图。假设我们的数据集采用了 CSV 文件形式 - Cricketers.csv

首先,导入所需的 3 个库 -

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

将数据从 CSV 文件加载至 Pandas DataFrame 中 -

dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers.csv")

使用 Age 和 Weight 列绘制点图 -

sb.pointplot(x =dataFrame["Age"], y = dataFrame["Weight"], data = dataFrame)

示例

如下是代码 -

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

# Load data from a CSV file into a Pandas DataFrame
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers.csv")

# plotting point plot with Age and Weight column
sb.pointplot(x =dataFrame["Age"], y = dataFrame["Weight"], data = dataFrame)

# label
plt.ylabel("Weight (kgs)")

# display
plt.show()

输出

将会产生如下输出 -

示例

让我们来看另一个设置了 hue 参数的示例 -

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

# Load data from a CSV file into a Pandas DataFrame
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers.csv")

# plotting point plot with Age and Weight column
# we have set the hue parameter as Role columns
sb.pointplot(dataFrame['Age'],dataFrame['Weight'], hue=dataFrame['Role'])

# label
plt.ylabel("Weight (kgs)")

# display
plt.show()

输出

将会产生如下输出 -

更新时间:01-Oct-2021

283 人次浏览

踢start Career

完成课程以获得认证

开始
广告