Skip to main content
 首页 » 编程设计

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

2024年10月24日16xxx_UU

我找到了 Gnuplot package 的文档对于 python 有点欠缺。我想做像 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) 

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