typeerror in basic example for legend handles in matplotlib

后端 未结 3 1873
独厮守ぢ
独厮守ぢ 2021-01-19 20:23

I have difficulties to understand the legend handling. The more, the basic example from the official matplotlib legend guide

import matplotlib.pyplot as plt         


        
3条回答
  •  轮回少年
    2021-01-19 20:39

    I had the same error some while back, but the fixes suggested above didn't work for me. I updated my version of matplotlib as well, but this didn't help.

    What did work was removing the handles argument and which plots to label altogether in the legend() method; like this:

        plot1 = plt.plot([1,2,3], 'b', label = 'first plot')
        plot2 = plt.plot([3,2,1], 'r', label = 'second plot')
        plt.legend()
        plt.show()
    

    Which rendered nicely to this:

提交回复
热议问题