Issue with pie chart matplotlib - startangle / len()
<p>I have a script which creates a pie chart based on CSV files. My problem started when I was reading a CSV that had only one row (e.g. <code>percent = [100]</code>). Is there any limitation of using a pie chart, where is will not show 100% for only one item? It seems that the error is related to either the <code>startangle</code> or <code>explode</code> arguments.</p>

<p>My code is:</p>

<pre><code>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()
</code></pre>

<p>Error in the line of startangle=70:</p>

<pre><code>if len(x) != len(explode):
TypeError: object of type 'float' has no len()
</code></pre>

<p>Thanks!</p>

<p>Change the <code>explode</code> parameter to a <code>list</code>:</p>

<pre><code>percent = [100]
explode = [0]

plt.pie(percent, explode=explode, ...)
</code></pre>

<p>If you have more values, you can use a <code>tuple</code>, but with one value <code>(int)</code> is seen as an integer:</p>

<pre><code>&gt;&gt;&gt; type((0))
&lt;type 'int'&gt;
&gt;&gt;&gt; type((0, 1))
&lt;type 'tuple'&gt;

&gt;&gt;&gt; type([0])
&lt;type 'list'&gt;
</code></pre>

python matplotlib charts