geatpy icon indicating copy to clipboard operation
geatpy copied to clipboard

Jupyter里 drawing=2 (动画模式)时报错

Open da2la opened this issue 2 years ago • 8 comments

Describe the bug 请问如何在Jupyter里显示动画?

To Reproduce Steps to reproduce the behavior:

  1. 在Jupyter的一个单元格里,把drawing从1改为2后
  2. 运行
  3. 循环出现新的空白图,以及一串说明: No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.
  4. 程序无法自行停止,只能手动结束运行。

Expected behavior 我理解Jupyter的一些机制可能不适合出现动画。但是,有没有办法可以在运算完成后生成我所需要的GIF。

Screenshots 1

Desktop (please complete the following information):

  • OS: Windows 10
  • VSCode 1.64 + Jupyter V2022.1
  • Python 3.8.12
  • Geatpy 2.7

Additional context 我想在Google Colab里运行我的代码(因为目标和变量都很多很复杂),而且需要动画(向他人展示),所以不得不用Jupyter来处理这个问题。

da2la avatar Mar 01 '22 08:03 da2la

绘制动画后,会保存gif动画文件。打开就可以显示了。至于如何在Jupyter上显示matplotlib的动画,你可以网上搜索资料解决。

geatpy-dev avatar Mar 02 '22 01:03 geatpy-dev

绘制动画后,会保存gif动画文件。打开就可以显示了。至于如何在Jupyter上显示matplotlib的动画,你可以网上搜索资料解决。

我按网上的说明,在最开始加了 %matplotlib notebook

现在这串代码只是不在下面循环显示空白图像了,但看起来依然陷入了无限循环中。

直接运行py文件,这串代码跑了大概1分16秒。 222

但是Jupyter里一直无法自动停止。 333

da2la avatar Mar 02 '22 02:03 da2la

你可以在jupyter里面手动用matplotlib绘图,调试OK后,用手写的绘图代码执行。

geatpy-dev avatar Mar 06 '22 15:03 geatpy-dev

我在测试函数示例中遇到同样问题,原始代码在jupyter和 .py 中都试过,同样报错: No artists with labels found to put in legend. Note that artists whose label start with an underscore are ignored when legend() is called with no argument.

problem = ea.benchmarks.DTLZ1()  # 生成问题对象
# 构建算法
algorithm = ea.moea_NSGA3_templet(problem,
                                  ea.Population(Encoding='RI', NIND=100),
                                  MAXGEN=500,  # 最大进化代数。
                                  logTras=1)  # 表示每隔多少代记录一次日志信息,0表示不记录。
# 求解
res = ea.optimize(algorithm, verbose=True, drawing=1, outputMsg=True, drawLog=True, saveFlag=True, dirName='result')

image image 感觉是pyplot.legend()出了问题,但是简单看了一下源码,好像默认参数没问题,目前没有debug。

RebelYoung avatar Jan 20 '23 01:01 RebelYoung

来信收到。谢谢。徐明

xm1490 avatar Jan 20 '23 01:01 xm1490

Thank you. Your email is received and will be handled as soon as possible

zeroraiser avatar Jan 20 '23 01:01 zeroraiser

您好,您的邮件冯颖已收到!

zzxzfy avatar Jan 20 '23 01:01 zzxzfy

原因是 matplotlib 新版本将 3D 绘图进行了更新. 修改方法

  • matplotlib 版本3.2.2可以用, 降级 matplotlib
  • 修改源码:
    • https://github.com/geatpy-dev/geatpy/blob/28835af9a7069823211cbe83d4c1bc2311e7970b/geatpy/visualization/PointScatter.py#L90
    • https://github.com/geatpy-dev/geatpy/blob/28835af9a7069823211cbe83d4c1bc2311e7970b/geatpy/visualization/PointScatter.py#L135
    • 都改成self.ax = self.fig.add_subplot(111, projection='3d') # 创建绘图区域

zhuhu00 avatar Feb 28 '24 06:02 zhuhu00