如何在python中绘制两个变量的数学表达式? [英] How can I plot a mathematical expression of two variables in python?

查看:33
本文介绍了如何在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)

我想在 t 的每个时间步绘制所有 z 的结果,结果如下:

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

但我不知道怎么做.我确定这很简单,但我不习惯在 python 中这样做.

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

推荐答案

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

这篇关于如何在python中绘制两个变量的数学表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆