Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3D Plotting Broken #529

Open
jordan-gleeson opened this issue Jun 4, 2024 · 1 comment
Open

3D Plotting Broken #529

jordan-gleeson opened this issue Jun 4, 2024 · 1 comment

Comments

@jordan-gleeson
Copy link

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):

  • OS: Google Colab
  • PySwarms Version: 1.2.0
  • Python Version: 3.10.12
@100jnle
Copy link

100jnle commented Jun 18, 2024

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

if canvas is None:
fig, ax = plt.subplots(1, 1, figsize=designer.figsize)
else:
fig, ax = canvas
# Initialize 3D-axis
ax = Axes3D(fig)

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.

sphere_swarm.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants