Python 属性错误:';图例';对象没有属性';可拖动';

Python 属性错误:';图例';对象没有属性';可拖动';,python,matplotlib,plot,legend,Python,Matplotlib,Plot,Legend,我正在使用pydiffusion模块绘制与扩散相关的图。我试图运行以下代码,但我得到了主题中提到的错误。 我在谷歌的帮助下添加了“draggable()”,但没用。 我没有太多的资源用于pydiffusion 请给我你的意见。非常感谢。 这是密码 import numpy as np import matplotlib.pyplot as plt import pandas as pd from pydiffusion.core import DiffSystem from pydiffusio

我正在使用pydiffusion模块绘制与扩散相关的图。我试图运行以下代码,但我得到了主题中提到的错误。 我在谷歌的帮助下添加了“draggable()”,但没用。 我没有太多的资源用于pydiffusion 请给我你的意见。非常感谢。 这是密码

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pydiffusion.core import DiffSystem
from pydiffusion.utils import step, mesh
from pydiffusion.simulation import mphSim
from pydiffusion.plot import profileplot, DCplot

diffsys = DiffSystem(Xr=[0, 1], X=[0, 1], DC=[1e-14, 1e-14], name='Constant D')
dis = mesh(0, 1000, 501)
profile_init = step(dis, 500, diffsys, name='Intitial step profile')

fig = plt.figure(figsize=(16, 6))
ax1, ax2 = fig.add_subplot(121), fig.add_subplot(122)
ax1.set_title('Diffusion Coefficients', fontsize=15)
ax2.set_title('Initial Step Profile', fontsize=15)
DCplot(diffsys, ax1)
profileplot(profile_init, ax2)
输出

啮合完成。最小网格=2.000,最大网格=2.000

AttributeError回溯(最近一次调用)
在里面
6 ax1.集合标题(“扩散系数”,fontsize=15)
7 ax2.设置标题(“初始步骤配置文件”,fontsize=15)
---->8 DCplot(diffsys,ax1)
9 profileplot(配置文件初始化,ax2)
DCplot中的~\Anaconda3\lib\site packages\pydiffusion\plot.py(diffsys、ax、err、**kwargs)
206支腿=最大。图例(numpoints=1,fontsize=leg\u fontsize)
207支腿。获取框架()。设置线宽(0.0)
-->208支腿。可拖动()
209 plt.紧密布局()
210
AttributeError:“图例”对象没有属性“可拖动”```
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
错误结束
**以下是“获得图”和“预期图”
[![已获得][1][1]
[![预期][2][2]
[1]: https://i.stack.imgur.com/hkzMg.png
[2]: https://i.stack.imgur.com/7QRMU.png**

legend.legend.draggable
已弃用,并于2019年5月在matplotlib 3.1.0中替换为
legend.legend.set_draggable()
。我想这是你的案子。检查版本。显而易见的解决方案是使用matplotlib的旧版本来运行代码。@Poolka感谢您的评论。我没有提到“legend”的任何代码行。您能告诉我您提到的代码应该添加到哪里吗?我对DCplot和profileplot非常陌生。在我使用plot之前,我不知道它们的语法。请给我确切的代码。谢谢,问题不在于代码本身。这是关于版本和兼容性的。检查当前使用的
matplotlib
pydiffusion
的版本。要解决此问题,应使用较旧版本的
matplotlib
(早于3.1.0)或较新版本的
pydiffusion
(根据pypi.org,最新版本为0.2.1)。这两种方法都会有帮助。目前,我有一个matplotlib版本的3.1.0和pydiffusion版本的0.2.1。感谢you@Poolka问题解决了,我不得不将pydiffusion更新为0.2.3。再次感谢您抽出时间在此写作。
legend.legend.draggable
已被弃用,并于2019年5月在matplotlib 3.1.0中被替换为
legend.legend.set_draggable()
。我想这是你的案子。检查版本。显而易见的解决方案是使用matplotlib的旧版本来运行代码。@Poolka感谢您的评论。我没有提到“legend”的任何代码行。您能告诉我您提到的代码应该添加到哪里吗?我对DCplot和profileplot非常陌生。在我使用plot之前,我不知道它们的语法。请给我确切的代码。谢谢,问题不在于代码本身。这是关于版本和兼容性的。检查当前使用的
matplotlib
pydiffusion
的版本。要解决此问题,应使用较旧版本的
matplotlib
(早于3.1.0)或较新版本的
pydiffusion
(根据pypi.org,最新版本为0.2.1)。这两种方法都会有帮助。目前,我有一个matplotlib版本的3.1.0和pydiffusion版本的0.2.1。感谢you@Poolka问题解决了,我不得不将pydiffusion更新为0.2.3。再次感谢您抽出时间在这里写信。
    AttributeError                            Traceback (most recent call last)
<ipython-input-37-6c67cfa7613d> in <module>
      6 ax1.set_title('Diffusion Coefficients', fontsize=15)
      7 ax2.set_title('Initial Step Profile', fontsize=15)
----> 8 DCplot(diffsys, ax1)
      9 profileplot(profile_init, ax2)

~\Anaconda3\lib\site-packages\pydiffusion\plot.py in DCplot(diffsys, ax, err, **kwargs)
    206     leg = ax.legend(numpoints=1, fontsize=leg_fontsize)
    207     leg.get_frame().set_linewidth(0.0)
--> 208     leg.draggable()
    209     plt.tight_layout()
    210 

AttributeError: 'Legend' object has no attribute 'draggable'     ```


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
end of the error


**Below are the 'obtained plot' and 'expected plot'
[![obtained][1]][1]
[![Expected][2]][2]
  [1]: https://i.stack.imgur.com/hkzMg.png
  [2]: https://i.stack.imgur.com/7QRMU.png**