3
我的目標是創建一個簡單的函數,該函數使用已繪製的變量的名稱標題圖形。如何在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));
而且它是:
plt.title("%s customers with filter less/greater...")
我喜歡它說:
plt.title("%s customers with %s less/greater...")
目前唯一的解決辦法,我可以想想涉及製作我想要避免的變量字典。任何和所有的援助非常感謝。
相關:http://stackoverflow.com/questions/2553354/how-to-get-a-variable -name作爲一種串式的Python – cel