小编W. *_*ett的帖子

如何在matplotlib中将变量名称打印为标题

我的目标是创建一个简单的函数,为带有已绘制变量名称的图形添加标题。

到目前为止,我有:

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)

目前,我能想到的唯一解决方案是为我的变量制作一个字典,这是我想避免的。任何帮助都将不胜感激。

python matplotlib

5
推荐指数
1
解决办法
7011
查看次数

标签 统计

matplotlib ×1

python ×1