📌  相关文章
📜  如何使用 Seaborn 中的数据点制作 Violinpot?

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

如何使用 Seaborn 中的数据点制作 Violinpot?

小提琴情节扮演类似的活动,通过须线或箱线图进行。因为它显示了一个或多个分类变量的多个定量数据。在多个单元显示多个数据可能是一种有效且有吸引力的方式。 “宽格式”数据框有助于维护可以绘制在图形上的每个数字列。可以使用 NumPy 或Python对象,但最好使用 Pandas 对象,因为关联的名称将用于注释轴。在本文中,我们将看到如何使用数据点制作小提琴图。

让我们先创建一个简单的小提琴手:

Python3
# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
  
seaborn.violinplot(x='day', y='tip', data=tip)


Python3
# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                   data = tip) 
  
seaborn.stripplot(x = "day", y = "tip", 
                  color = 'black',
                  data = tip)


Python3
# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                data = tip) 
  
seaborn.swarmplot(x ='day', y ='tip',
                  data = tip,
                  color = "white")


Python3
# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                data = tip, inner = "points")


输出:

方法 1:使用带状图。

蟒蛇3

# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                   data = tip) 
  
seaborn.stripplot(x = "day", y = "tip", 
                  color = 'black',
                  data = tip)

输出:

方法2:使用swarmplot。

蟒蛇3

# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                data = tip) 
  
seaborn.swarmplot(x ='day', y ='tip',
                  data = tip,
                  color = "white")

输出:

方法三:使用内点参数。

蟒蛇3

# Python program to illustrate 
# violinplot using inbuilt data-set 
# given in seaborn 
      
# importing the required module 
import seaborn  
    
# use to set style of background of plot 
seaborn.set(style = 'whitegrid')  
    
# loading data-set 
tip = seaborn.load_dataset('tips') 
    
seaborn.violinplot(x ='day', y ='tip',
                data = tip, inner = "points") 

输出: