python - 比较来自相同数据的 MATLAB 和 Python 图像之间的差异

标签 python matlab matplotlib

我在 python 和 MATLAB 中绘制相同的值( The data 完全相同)。

只是在做

import scipy.io as sio
zzz = sio.loadmat(pathToData)
plot(zzz['zzz'][:,0]) #python

在Matlab中

plot(zzz)        %matlab

我试图让 matplotlib 创建一个看起来与 MATLAB 图相同的图像,例如 this example .

  • 以下图像是通过屏幕截图创建的,以避免对图像进行任何后期处理。我确保两个人物的尺寸相同。然后我将一个放在另一个旁边并同时创建它们的屏幕截图

我还将这些行并排放置: enter image description here

enter image description here

这有点难以看出,但是 MATLAB 图像的噪声要大得多,而且看起来 python 图像是经过类似这样的移动平均值之后的(尤其是在绘图的开头)

关于如何使 Python 图形看起来完全像 MATLAB 图形,您有什么建议吗?

(我上传了the data如果有人对一些实验感兴趣的话)

编辑

我尝试做 antialiased = False,结果好一点,但是无论我尝试做多小,线宽都更大(original screencapture)

enter image description here

最佳答案

我认为这是由于 matplotlib 使用 anti aliasing生成图形时。但是,这是您可以设置的艺术家属性:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2*np.pi, 500)

plt.plot(x, np.sin(x), label='with anti-aliasing')
plt.plot(x, np.cos(x), antialiased=False, label='without anti-aliasing')
plt.legend()
plt.show()

结果:

enter image description here

放大左上角:

enter image description here

因此,通过关闭抗锯齿滤波器,您可能会得到与 Matlab 版本非常相似的结果。

关于python - 比较来自相同数据的 MATLAB 和 Python 图像之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30828617/

相关文章:

Python Sqlite3 将 BLOB 传递给用户定义的函数给出 None

python - 使用 Paramiko 向 BOSCLI shell 发送命令

matlab - 尝试将脚本作为函数执行

matlab - 如何检测屏幕上任意位置的鼠标位置?

python - Matplotlib - 标记每个 bin

python - matplotlib 绘制条形图和折线图在一起

python - 在 Tkinter 中显示 matplotlib 条形图

python - 如何在类中并行化 python 中的 for?

c++ - 添加高斯噪声

python - [matplotlib] : write dates on x axis