【问题标题】:Python plot legend is not draggable. gives an errorPython 绘图图例不可拖动。给出错误
【发布时间】:2015-04-11 06:36:03
【问题描述】:

我有数据,我正在尝试制作情节。它确实会产生情节,但图例不可拖动。它给了我下面提到的错误。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import ast
...................
...................
.
.
.
.
.   

fig, ax = plt.subplots()

for f in datafile:
    plt.plot(f[0],f[1])




plt.tick_params(axis='both', which='major', labelsize=15)
plt.legend(datanames)
plt.legend(loc='best', numpoints=1)
plt.legend().draggable()    


plt.grid()  
plt.show()

我正在尝试情节,它给了我一个错误

AttributeError: 'NoneType' 对象没有属性 'draggable'

如何解决?

【问题讨论】:

标签: python matplotlib plot legend


【解决方案1】:

每次调用plt.legend 时,它都会创建一个 图例(丢弃旧图例)。你们中没有一个艺术家有标签,所以不会创建图例,plt.legend 返回None。就这样做吧:

legend = plt.legend(datanames, loc='best', numpoints=1)
legend.draggable() 

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 1970-01-01
    • 2023-03-30
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多