在seaborn中用色调参数分割小提琴图

时间:2015-11-16 22:21:57

标签: python matplotlib seaborn

我正在尝试仅使用violinplot中的yhue参数来设置seabornx数据变量定义为无)。使用我所做文档中的类似示例:

tips = sns.load_dataset("tips")
sns.violinplot(y="total_bill", hue="sex", data=tips, split=True)

结果图不会根据色调变量进行分割。

enter image description here

定义x变量时,绘图将被分割。有没有办法在没有x输入的情况下在seaborn中进行拆分?

1 个答案:

答案 0 :(得分:15)

只需为所有条目添加一个相同的变量,并将其用作data = {'Cities': {'Des_Moines': 80.0, 'Lubbock': -300.0, 'Minneapolis': 85.7, 'Orange_County': 80.0, 'Salt_Lake_City': 81.8, 'San_Diego': 80.0, 'San_Francisco': -400.0, 'Troy': -400.0, 'Wilmington': -300.0}} from bokeh.plotting import figure, show from bokeh.models import Range1d from bokeh.palettes import Greens9 import numpy as np cities = data['Cities'] p = figure(width=400, height=400) bottom = -1 ii = -1 for k,v in cities.iteritems(): bottom = bottom+1 top = bottom+1 left = 0 right = cities[k] ii += 1 p.quad(top=top, bottom=bottom, left=left, right=right, color=Greens9[ii]) #"#B3DE69") min_city = min(cities, key=cities.get) max_city = max(cities, key=cities.get) p.x_range = Range1d(start=cities[min_city], end=cities[max_city]) show(p) # Can be done with rect glyph: #p = figure(width=400, height=400) #p.rect(x=[1, 2, 3], y=[1, 2, 3], width=0.2, height=40, color="#CAB2D6", # angle=np.pi/2, height_units="screen")

x

enter image description here