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

标签 python gnuplot

我找到了 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)

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

关于python - 如何在 python 的 gnuplot 模块中绘制图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32206533/

相关文章:

Python 脚本不会运行

audio - 在 gnuplot 中绘制音频数据

带绘图线的 Gnuplot 直方图

gnuplot - 绘制两个具有不同时间格式的文件

python - 序列化时 Protobuf 默认与 "missing required fields"

python - 我无法理解 django-markdownx 的用法

python - 使用 multiprocessing.pool.map 通过同一个套接字发送

python - 如何结合两个直方图python

matrix - Gnuplot:制作用矩阵生成的 map 的 gif?

c++ - fprintf 不写入管道