2016-09-14 11 views
-2

CSVファイルに基づいて円グラフを作成するスクリプトがあります。私の問題は、行が1つしかないCSV(たとえばpercent = [100])を読んでから始まりました。円グラフを使用する場合、1つのアイテムに対して100%表示されない点がありますか?このエラーは、startangleまたはexplode引数のいずれかと関連しているようです。円グラフの問題matplotlib - startangle/len()

私のコードは次のとおりです。

percent = [100] 

plt.pie(percent,  # data 
    explode=(0),  # offset parameters 
    #labels=country, # slice labels - removed to hid labels and added labels=country in legend() 
    colors=colors,  # array of colours 
    autopct='%1.0f%%', # print the values inside the wedges - add % to the values 
    shadow=False,  # enable shadow 
    startangle=70  # starting angle 
) 

plt.axis('equal') 
plt.legend(loc='best', labels=country) 
plt.tight_layout() 

startAngleの= 70の行でエラーが発生しました:

if len(x) != len(explode): 
TypeError: object of type 'float' has no len() 

ありがとう!

答えて

1

変更listからexplodeパラメータ:

percent = [100] 
explode = [0] 

plt.pie(percent, explode=explode, ...) 

あなたはより多くの価値を持っている場合は、あなたがtupleを使用することができますが、一つの値(int)で整数として見られている:

>>> type((0)) 
<type 'int'> 
>>> type((0, 1)) 
<type 'tuple'> 

>>> type([0]) 
<type 'list'> 
+0

あなたが解決私の問題。ありがとう! – Gonzalo

関連する問題