AttributeError: 'ErrorbarContainer' object has no attribute 'set_ylim'
<p>I am plotting the results of some experiments with error bars. I'd like to be able to set the y limit in the case of results with extreme outliers that aren't interesting. This code:</p>

<pre><code>axes = plt.errorbar(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index, chi_square_y, yerr=chi_square_y_error, fmt = 'o')
axes.set_ylim([-.2, .2])
plt.plot((min(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index), max(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index)), (0, 0), 'r--', linewidth = 2)
</code></pre>

<p>produces this error:</p>

<pre><code>AttributeError                            Traceback (most recent call last)
&lt;ipython-input-79-794286dd3c29&gt; in &lt;module&gt;()
     18 rcParams['figure.figsize'] = 10, 5
     19 axes = plt.errorbar(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index, chi_square_y, yerr=chi_square_y_error, fmt = 'o')
---&gt; 20 axes.set_ylim([-.2, .2])
     21 plt.plot((min(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index), max(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index)), (0, 0), 'r--', linewidth = 2)

AttributeError: 'ErrorbarContainer' object has no attribute 'set_ylim'
</code></pre>

<p>How can I set the y limits?</p>

<p>Thanks!</p>

<p>Simply use the <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.ylim" rel="nofollow">matplotlib.pyplot.ylim()</a> function.</p>

<p>Your example is not self-contained, so I cannot check that the below code actually works, but at least the mentioned error will be fixed:</p>

<pre><code>plt.errorbar(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index, chi_square_y, yerr=chi_square_y_error, fmt = 'o')
plt.ylim(-.2, .2)
plt.plot((min(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index), max(feature_data[feature_data.num_unique[feature_of_interest] &gt; 1].index)), (0, 0), 'r--', linewidth = 2)
</code></pre>

python matplotlib