学python还是matlab_仅就作图而言,python和matlab有可比性吗?

个人认为:仅作图而言,MATLAB 代码更简单,且比 Python 好看。

我们绘制两条曲线:

不要错过 免费学习Python的机会,快来+688244617

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

,并在图中插入一个公式

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

Python 代码如下:

import numpy as np

import cv2

from matplotlib import pyplot as plt

x = np.linspace(0,10,1000)

y=np.sin(x)

z=np.cos(x**2)

plt.plot(x,y,label=r"$\sin(x)$",color="red")

plt.plot(x,z,"b--",label=r"$\cos(x^2)$")

plt.text(0,0,r"$\int_a^b f(x)\mathrm{d}x$")

plt.xlabel("Time(s)")

plt.ylabel("Volt")

plt.title("PyPlot Example")

plt.ylim(-1.2,1.2)

plt.legend()

plt.show()

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

Python 绘制结果

接下来是高度相同的 MATLAB 代码:

x=linspace(0,10,1000);

y=sin(x);

z=cos(x.^2);

plot(x,y,'Color','r')

hold on

plot(x,z,"b--")

text(0,0,'$\int_a^b f(x)\mathrm{d}x/pre>,'Interpreter','latex')

xlabel("Time(s)")

ylabel("Volt")

title("MatlabPlot Example")

ylim([-1.2 1.2])

legend('$\sin(x)/pre>,'$\cos(x^2)/pre>,'Interpreter','latex')

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

MATLAB 绘制结果

如果你是 究极排版狂魔 ,那么这个神级工具包你一定不会错过—— matlab2tikz,能将 MATLAB 当前窗口中的的图像转化为 LaTeX 源代码:

\begin{tikzpicture}

\begin{axis}[%

width=4.525in,

height=3.568in,

at={(0.759in,0.482in)},

scale only axis,

xmin=0,

xmax=10,

xlabel style={font=\color{white!15!black}},

xlabel={Time(s)},

ymin=-1.2,

ymax=1.2,

ylabel style={font=\color{white!15!black}},

ylabel={Volt},

axis background/.style={fill=white},

title={\LaTeX Plot Example},

legend style={legend cell align=left, align=left, draw=white!15!black}

]

\addplot [color=red]

table[row sep=crcr]{%

0 0\\

0.01001001001001 0.0100098428431792\\

0.02002002002002 0.0200186827054735\\

0.03003003003003 0.0300255167064961\\

...

9.96996996996997 0.426059444079512\\

9.97997997997998 0.59706053061497\\

9.98998998998999 0.744463820622945\\

10 0.862318872287684\\

};

\addlegendentry{$\cos(x^2)$}

\node[right, align=left]

at (axis cs:0,0) {$\int_a^b f(x)\mathrm{d}x$};

\end{axis}

\begin{axis}[%

width=5.839in,

height=4.378in,

at={(0in,0in)},

scale only axis,

xmin=0,

xmax=1,

ymin=0,

ymax=1,

axis line style={draw=none},

ticks=none,

axis x line*=bottom,

axis y line*=left,

legend style={legend cell align=left, align=left, draw=white!15!black}

]

\end{axis}

\end{tikzpicture}%

9daac748cec4

仅就作图而言,python和matlab有可比性吗?

LaTeX 绘制结果

这样比较下来,MATLAB 在代码简洁方面略胜,在图像精美程度方面完胜。

对此,你有什么想法,欢迎在下方评论!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值