Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matlab到Matplotlib_Python_Matlab_Matplotlib - Fatal编程技术网

Python Matlab到Matplotlib

Python Matlab到Matplotlib,python,matlab,matplotlib,Python,Matlab,Matplotlib,我想将两段Matlab代码转换为Python/Matplotlib 这里是第一个片段 Xs = 1.8; fs = 10; fi = pi/3; t1 = -0.1; t2 = 0.2; t = [t1, t2]; x = inline('Xs * sin(2 * pi * fs * t + fi)','t','Xs','fs','fi'); fplot(x, t, 2e-3, 1,'-', Xs, fs, fi) xlabel('t'); ylabel('x_s'); grid on t

我想将两段Matlab代码转换为Python/Matplotlib

这里是第一个片段

Xs = 1.8;
fs = 10; 
fi = pi/3;

t1 = -0.1;
t2 = 0.2;
t = [t1, t2];

x = inline('Xs * sin(2 * pi * fs * t + fi)','t','Xs','fs','fi');
fplot(x, t, 2e-3, 1,'-', Xs, fs, fi)
xlabel('t'); ylabel('x_s'); grid on
title('x_s(t) = X_s sin(2 \pi f_s t + \phi_s)')
我可以将前6个SLOC转换为python,因为它们是基本的变量赋值。但是,对于SLOC 7,我不知道Matplotlib中的Matlab inline()函数的等价物,假设有。我已经搜索了Numpy名称空间,但没有名为“inline”的函数。在运行代码时,我还收到一条验证上述语句的错误消息。此外,在SLOC 8上,我在Matplotlib中找不到与fplot()函数及其某些参数的格式等效的函数。fplot()函数也不在Pylab命名空间中

第二个片段与第一个片段没有太大的不同,我将发布它,作为对上述内容的补充:

x = inline('Xe*exp(b*t)','t','Xe','b');

Xe  = 0.8; 
b = -0.5;

t1 = 0;
t2 = 8;
t = [t1, t2];

fplot(x,t,2e-3,1,'-',Xe,b)
xlabel('t')
ylabel('x_e')
title('x_e(t) = X_e e^{b t}')
grid on
我对Matlab和Python/Matplotlib都没有什么经验,但是,我已经成功地将其他一些Matlab代码片段转换为Matplotlib。我正在为学校制作一个公文包,需要我使用Matlab绘图。然而,Matlab不是免费的,所以我选择使用Matplotlib


提前感谢您提供的任何帮助。

对于“内联”等价物,您可以使用“lambda”函数。

您能给我一些更多的信息,也许是lambda函数的一个示例,它可以实现上述内联代码片段中的一个功能吗?@rgb one,例如
x=lambda t,Xe,b:Xe*exp(b*t)
,以前从numpy导入exp定义的