我正在尝试仅使用violinplot
中的y
和hue
参数来设置seaborn
(x
数据变量定义为无)。使用我所做文档中的类似示例:
tips = sns.load_dataset("tips")
sns.violinplot(y="total_bill", hue="sex", data=tips, split=True)
结果图不会根据色调变量进行分割。
定义x变量时,绘图将被分割。有没有办法在没有x输入的情况下在seaborn中进行拆分?
答案 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