📜  Python – seaborn.jointplot() 方法

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

Python – seaborn.jointplot() 方法

Seaborn是一个基于 matplotlib 的Python数据可视化库。它提供了一个用于绘制有吸引力和信息丰富的统计图形的高级界面。 Seaborn 帮助解决了 Matplotlib 面临的两大问题;问题是什么?

  • 默认 Matplotlib 参数
  • 使用数据框

随着 Seaborn 对 Matplotlib 的补充和扩展,学习曲线非常缓慢。如果您了解 Matplotlib,那么您已经完成了 Seaborn 的一半。

seaborn.jointplot() :

用双变量和单变量图绘制两个变量的图。这个函数为“JointGrid”类提供了一个方便的接口,有几种固定的绘图类型。这旨在成为一个相当轻量级的包装器;如果你需要更多的灵活性,你应该直接使用 :class:'JointGrid' 。

下面是上述方法的实现:

示例 1:

Python3
# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("attention")
  
# draw jointplot with
# hex kind
sns.jointplot(x = "solutions", y = "score",
              kind = "hex", 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("mpg")
  
# draw jointplot with
# scatter kind
sns.jointplot(x = "mpg", y = "acceleration",
              kind = "scatter", 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("exercise")
  
# draw jointplot with
# kde kind
sns.jointplot(x = "id", y = "pulse",
              kind = "kde", 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("titanic")
  
# draw jointplot with
# reg kind
sns.jointplot(x = "age", y = "fare",
              kind = "reg", data = data,
              dropna = True)
  
# 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("mpg")
  
# draw jointplot with
# scatter kind
sns.jointplot(x = "mpg", y = "acceleration",
              kind = "scatter", 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("exercise")
  
# draw jointplot with
# kde kind
sns.jointplot(x = "id", y = "pulse",
              kind = "kde", data = data)
# Show the plot
plt.show()
  
# This code is contributed
# by Deepanshu Rustagi.

输出:

示例 4:

Python3

# importing required packages
import seaborn as sns
import matplotlib.pyplot as plt
  
# loading dataset
data = sns.load_dataset("titanic")
  
# draw jointplot with
# reg kind
sns.jointplot(x = "age", y = "fare",
              kind = "reg", data = data,
              dropna = True)
  
# show the plot
plt.show()
  
# This code is contributed 
# by Deepanshu Rustagi.

输出: