How is order of items in matplotlib legend determined?

后端 未结 5 774
迷失自我
迷失自我 2020-12-12 17:43

I am having to reorder items in a legend, when I don\'t think I should have to. I try:

from pylab import *
clf()
ax=gca()
ht=ax.add_patch(Rectangle((1,1),1,1,         


        
5条回答
  •  萌比男神i
    2020-12-12 18:40

    The order is deterministic, but part of the private guts so can be changed at any time, see the code here (the self.* elements are lists of the artists that have been added, hence the handle list is sorted first by type, second by order they were added).

    If you want to explicitly control the order of the elements in your legend then assemble a list of handlers and labels like you did in the your edit.

提交回复
热议问题