Python – seaborn.pointplot() 方法
Seaborn是一个惊人的Python统计图形绘图可视化库。它提供了漂亮的默认样式和调色板,使统计图更具吸引力。它建立在 matplotlib 库之上,并且与 pandas 的数据结构紧密集成。
seaborn.pointplot() :
- 此方法用于使用散点图字形显示点估计值和置信区间。点图表示通过散点图点的位置对数值变量的集中趋势的估计,并使用误差条提供该估计周围的不确定性的一些指示。
- 此函数始终将其中一个变量视为分类变量,并在相关轴上的序数位置 (0, 1, ... n) 处绘制数据,即使数据具有数字或日期类型也是如此。
Syntax: seaborn.pointplot(x=None, y=None, hue=None, data=None, order=None,hue_order=None, estimator=
Parameters: The description of some main parameters are given below:
- x, y: Inputs for plotting long-form data.
- hue: (optional) column name for color encoding.
- data: dataframe as a Dataset for plotting.
- markers: (optional) Markers to use for each of the ‘hue’ levels.
- linestyles: (optional) Line styles to use for each of the ‘hue’ levels.
- dodge: (optional) Amount to separate the points for each level of the ‘hue’ variable along the categorical axis.
- color: (optional) Color for all the elements, or seed for a gradient palette.
- capsize: (optional) Width of the ‘caps’ on error bars.
Return: The Axes object with the plot drawn onto it.
下面是上述方法的实现:
示例 1:
Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# draw pointplot
sns.pointplot(x = "sex",
y = "total_bill",
data = data)
# show the plot
plt.show()
# This code is contributed
# by Deepanshu Rustagi.
Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# draw pointplot with
# hue = smoker
sns.pointplot(x = "sex",
y = "total_bill",
hue = "smoker",
data = data)
# show the plot
plt.show()
# This code is contributed
# by Deepanshu Rustagi.
Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# draw pointplot
sns.pointplot(x = "size",
y = "total_bill",
linestyles = '-.',
markers = '^',
hue = "sex",
data = data)
# show the plot
plt.show()
# This code is contributed
# by Deepanshu Rustagi.
输出:
示例 2:
Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# draw pointplot with
# hue = smoker
sns.pointplot(x = "sex",
y = "total_bill",
hue = "smoker",
data = data)
# show the plot
plt.show()
# This code is contributed
# by Deepanshu Rustagi.
输出 :
示例 3:
Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
# loading dataset
data = sns.load_dataset("tips")
# draw pointplot
sns.pointplot(x = "size",
y = "total_bill",
linestyles = '-.',
markers = '^',
hue = "sex",
data = data)
# show the plot
plt.show()
# This code is contributed
# by Deepanshu Rustagi.
输出: