我的目标是创建一个简单的函数,为带有已绘制变量名称的图形添加标题。
到目前为止,我有:
def comparigraphside(rawvariable, filtervariable, cut):
variable = rawvariable[filtervariable > 0]
upperbound = np.mean(variable) + 3*np.std(variable)
plt.figure(figsize=(20,5))
plt.subplot(121)
plt.hist(variable[filtervariable <= cut], bins=20, range=(0,upperbound), normed=True)
plt.title("%s customers with filter less than or equal to %s" % (len(variable[filtervariable <= cut]), cut))
plt.subplot(122)
plt.hist(variable[filtervariable > cut], bins=20, range=(0,upperbound), normed=True)
plt.title("%s customers with filter greater than %s" % (len(variable[filtervariable > cut]), cut));
Run Code Online (Sandbox Code Playgroud)
在哪里:
plt.title("%s customers with filter less/greater...")
Run Code Online (Sandbox Code Playgroud)
我很乐意说:
plt.title("%s customers with %s less/greater...")
Run Code Online (Sandbox Code Playgroud)
目前,我能想到的唯一解决方案是为我的变量制作一个字典,这是我想避免的。任何帮助都将不胜感激。