2
在定義了ax1=fig1.add_subplot(111)
並繪製了8個數據系列以及相關的label
值後,我使用以下代碼行添加圖例。Pyplot圖例索引錯誤:元組索引超出範圍
ax1.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
我以前多次已經利用這種方法沒有問題,但這次它會產生一個錯誤說IndexError: tuple index out of range
Traceback (most recent call last):
File "interface_tension_adhesion_plotter.py", line 45, in <module>
ax1.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 564, in legend
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/legend.py", line 386, in __init__
self._init_legend_box(handles, labels, markerfirst)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/legend.py", line 655, in _init_legend_box
fontsize, handlebox))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/legend_handler.py", line 119, in legend_artist
fontsize, handlebox.get_transform())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/legend_handler.py", line 476, in create_artists
self.update_prop(coll, barlinecols[0], legend)
IndexError: tuple index out of range
我不知道爲什麼會這樣,真的希望建議。
這似乎與繪製錯誤條有關。但爲了幫助你,你需要提供[mcve]。 – ImportanceOfBeingErnest
確實用誤差線繪製:'ax1.errorbar(tensionsarray,meanproportionsarray,yerr = stdproportionsarray,label =「adhsion = {:02.1f}」。format(l))' – crevell
這不是[mcve]。 [編輯]你的問題,如果你想提供更多的信息。 – ImportanceOfBeingErnest