My goal is to animate the hyper-specific (canonical) diffusion equation by being able to "tell" Python to increment the "t" variable existing in said equation. I have easily done this in Mathematica but need to use Python for my assigned research project.
The equation is structured/defined as c(x,y,t)
, and obviously my question applies for any type of function that c(x,y,t)
is set to equal. Every answer related to my question ether:
1) Does not include a function that is not a PDE
2) Consists of not incrementing a time variable (t)
Furthermore, I cannot find any method to graph a 3D equation on Python that is for 2 variables.
EDIT: I have figured out a way to do this.
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import random
def fun(x, t):
return x+t #Any equation
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.arange(-20.0, 20.0, 0.05)
t = np.arange(0.0,50.0,1)
X, Y = np.meshgrid(x, t)
zs = np.array([fun(x,t) for x,t in zip(np.ravel(X), np.ravel(Y))])
Z = zs.reshape(X.shape)
ax.plot_surface(X, Y, Z)
ax.set_xlabel('X Position')
ax.set_ylabel('Time')
ax.set_zlabel('Concentration')
plt.show()
Credit: Wim I want to use matplotlib to make a 3d plot given a z function
Any help or simple code of an animation procedure would mean a lot, as my research project deals with 7D mathematics and this is essentially the most basic example of a non-trivial representation of what I am trying to do. So expect more questions to come (regardless of an answer).