Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Scripts Modélisation du vivant
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bonnemains Matthieu
Scripts Modélisation du vivant
Commits
7f83cc0f
Commit
7f83cc0f
authored
1 month ago
by
Bonnemains Matthieu
Browse files
Options
Downloads
Patches
Plain Diff
Delete test.py
parent
b286ab78
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test.py
+0
-46
0 additions, 46 deletions
test.py
with
0 additions
and
46 deletions
test.py
deleted
100644 → 0
+
0
−
46
View file @
b286ab78
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.animation
as
animation
from
mpl_toolkits.mplot3d
import
Axes3D
# Function to visualize
def
function_to_plot
(
x
,
y
):
return
(
x
**
2
+
y
**
2
)
*
np
.
sin
(
np
.
sqrt
(
x
**
2
+
y
**
2
))
# Example function with minima
# 3D Plot Function
def
plot_3D
(
populations
,
function_to_plot
,
save_path
=
"
animation.gif
"
):
fig
=
plt
.
figure
(
figsize
=
(
10
,
7
))
ax
=
fig
.
add_subplot
(
111
,
projection
=
'
3d
'
)
# Generate grid for the surface plot
x
=
np
.
linspace
(
-
100
,
100
,
200
)
y
=
np
.
linspace
(
-
100
,
100
,
200
)
X
,
Y
=
np
.
meshgrid
(
x
,
y
)
Z
=
function_to_plot
(
X
,
Y
)
# Plot surface
ax
.
plot_surface
(
X
,
Y
,
Z
,
cmap
=
"
viridis
"
,
alpha
=
0.6
,
edgecolor
=
'
none
'
)
# Initialize scatter plot for moving points
scatter
=
ax
.
scatter
([],
[],
[],
color
=
'
red
'
,
s
=
1
,
alpha
=
0.8
)
# Update function for animation
def
update
(
frame
):
ax
.
collections
.
clear
()
# Clear previous points
points
=
populations
[
frame
]
# Get current positions
Z_points
=
function_to_plot
(
points
[:,
0
],
points
[:,
1
])
# Compute function values
scatter
=
ax
.
scatter
(
points
[:,
0
],
points
[:,
1
],
Z_points
,
color
=
'
red
'
,
s
=
1
,
alpha
=
0.8
)
return
scatter
,
# Create animation
ani
=
animation
.
FuncAnimation
(
fig
,
update
,
frames
=
len
(
populations
),
interval
=
100
,
blit
=
False
)
# Save animation as GIF
ani
.
save
(
save_path
,
writer
=
'
pillow
'
,
fps
=
20
)
plt
.
show
()
# Example Usage:
populations
=
[
np
.
random
.
uniform
(
-
100
,
100
,
size
=
(
20000
,
2
))
for
_
in
range
(
50
)]
# Fake data
plot_3D
(
populations
,
function_to_plot
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment