Created
February 10, 2025 15:24
-
-
Save alexlib/744bd8b606e6276db1e08c2d206f7417 to your computer and use it in GitHub Desktop.
From Mathworks LinkedIn post to Jupyter Notebook through Mistral Le Chat :) (https://www.linkedin.com/posts/the-mathworks_2_matlab-heart-ugcPost-7294671504095539200-leqV?utm_source=share&utm_medium=member_desktop)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib.animation as animation\n", | |
"\n", | |
"# Define the range for x and a\n", | |
"x = np.arange(-2, 2.005, 0.005)\n", | |
"a = np.arange(0, 1705, 5)\n", | |
"\n", | |
"# Initialize y with zeros\n", | |
"y = np.zeros_like(x)\n", | |
"\n", | |
"# Create a figure and a line object\n", | |
"fig, ax = plt.subplots()\n", | |
"line, = ax.plot(x, y, 'r')\n", | |
"\n", | |
"# Set the axis limits\n", | |
"ax.set_xlim(-2, 2)\n", | |
"ax.set_ylim(-2, 3)\n", | |
"\n", | |
"# Update function for the animation\n", | |
"def update(i):\n", | |
" y = np.cbrt(x**2) + 1.1 * np.sin(i * x) * np.sqrt(np.maximum(0, 4 - x**2))\n", | |
" line.set_ydata(y)\n", | |
" return line,\n", | |
"\n", | |
"# Create the animation\n", | |
"ani = animation.FuncAnimation(fig, update, frames=a, interval=100, blit=True)\n", | |
"\n", | |
"# Save the animation as a GIF\n", | |
"ani.save('heart.gif', writer='pillow')\n", | |
"# Display the animation\n", | |
"plt.show()\n" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "napari", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.12.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Author
alexlib
commented
Feb 10, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment