如何在 python 的 gnuplot 模块中绘制图像?

How do I do image plots in the gnuplot module for python?

我找到了 Gnuplot package for python a bit lacking. I want to do image plots like this simple one 的文档:

#!/usr/bin/gnuplot

plot '-' matrix with image
4 4 4 1
3 2 1 1
1 2 3 1
0 0 0 0
e

如何创建矩阵并告诉 Gnuplot.py 如何使用它并绘制图像?我假设它是这样的:

#!/usr/bin/python

import Gnuplot as gp
import numpy as np

g = gp.Gnuplot(debug=1)

m = np.matrix('4 4 4 1; 3 2 1 1; 1 2 3 1; 0 0 0 0')
gdat = gp.GridData(m, with_='matrix image', binary=0)

g.plot(gdat)

Gnuplot-py 是一个非常简约的 gnuplot 包装器,因此您必须提供大量原始命令。请尝试以下操作:

#!/usr/bin/python

import Gnuplot as gp
import numpy as np

g = gp.Gnuplot(debug=1)

m = np.matrix('4 4 4 1; 3 2 1 1; 1 2 3 1; 0 0 0 0')
gdat = gp.GridData(m, inline=True, binary=False)
g('set style data image')
g.plot(gdat)

目前我无法对此进行测试,但它应该可以帮助您入门。