ljvmiranda921 / pyswarms

A research toolkit for particle swarm optimization in Python
https://pyswarms.readthedocs.io/en/latest/
MIT License
1.25k stars 332 forks source link

3D Plotting Broken #529

Open jordan-gleeson opened 4 weeks ago

jordan-gleeson commented 4 weeks ago

Describe the bug Plotting in 3D space appears to be broken. The example in visualization.ipynb returns an empty 2D plot.

To Reproduce Open visualization.ipynb and run all code, then view plot1.gif.

Expected behavior A 3D visualization of the sphere optimization example.

Environment (please complete the following information):

100jnle commented 2 weeks ago

Hi,

I am not a developer, so this is a crude work-around, but in the plotters utility function, plot_surface in plotters.py, I was able to get an animation by editing the lines that initialize the figure.

I changed

https://github.com/ljvmiranda921/pyswarms/blob/70c969d929bb2dab6211765def0431680fc5cb01/pyswarms/utils/plotters/plotters.py#L343-L349

to

 if canvas is None:
        fig, ax = plt.subplots(1, 1, figsize=designer.figsize, subplot_kw={"projection":"3d"})
    else:
        fig, ax = canvas

    # Initialize 3D-axis
    # ax = Axes3D(fig)

and it worked, though the plot is a bit uglier.

https://github.com/ljvmiranda921/pyswarms/assets/131929434/61d5cad1-17b8-45d6-8885-7377deab9370