2017-04-01 69 views
1

我的問題是我想調用matplotlib函數中的變量,但它給了我一個錯誤。也許它不可能。Matplotlib直方圖標題

sigma = float(some number) 
ax1.hist(population) 
ax1.set_title('blah N = 241', 'standard deviation =',sigma) 

它會返回錯誤:

AttributeError: 'str' object has no attribute 'pop' 

AttributeError: 'int' object has no attribute 'pop' 

回答

1

documentationset_title表明,它不工作方式相同print。你提供了三個參數,第二個參數應該是dict(可以是pop -ed)。既然你傳遞了一個字符串,那就行不通了。

試試這個:

sigma = float(some number) 
ax1.hist(population) 
title = 'blah N = 241, ' + 'standard deviation =' + str(sigma) 
ax1.set_title(title) 
1

ax.set_title()要求的標題是一個字符串。你必須收集所有的字符串片段連接成一個字符串將它們傳遞給set_title函數之前:

ax1.set_title('blah N = 241' + 'standard deviation =' + str(sigma))