Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a mathematical expression of two variables in python?

I have a time- and depth-varying function, simplified to:

def f(z,t):
    return np.exp(-z)*np.sin(t-z)

z = np.linspace(0,3000,num=3001)
t = np.arange(0,40000,4000)

I want to plot the the result for all z at each time step in t, resulting in something like this:

enter image description here

but I don't know how. I'm sure it's very simple, but I'm not used to doing this in python.

like image 674
a different ben Avatar asked Dec 16 '22 16:12

a different ben


1 Answers

import matplotlib.pyplot as plt
import numpy as np

def f(z,t):
    return np.exp(-z)*np.sin(t-z)

z = np.linspace(0,5,3001)
t = np.arange(0,40000,4000)

for tval in t:
    plt.plot(z, f(z, tval))
plt.show()

enter image description here

like image 165
unutbu Avatar answered Jan 11 '23 08:01

unutbu