首页 > 解决方案 > AttributeError:“Legend”对象没有“可拖动”属性

问题描述

我正在使用 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                            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**

标签: pythonmatplotlibplotlegend

解决方案


推荐阅读